]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
Add callbacks for audio (un)initialization in the echo canceller calibrator.
[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 #ifdef USE_JAVAH
21 #include "linphonecore_jni.h"
22 #endif
23 #include "linphonecore_utils.h"
24 #include <ortp/zrtp.h>
25
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 #include "lpconfig.h"
35
36 #ifdef ANDROID
37 #include <android/log.h>
38 extern "C" void libmsilbc_init();
39 #ifdef HAVE_X264
40 extern "C" void libmsx264_init();
41 #endif
42 #ifdef HAVE_AMR
43 extern "C" void libmsamr_init();
44 #endif
45 #ifdef HAVE_SILK
46 extern "C" void libmssilk_init();
47 #endif
48 #ifdef HAVE_G729
49 extern "C" void libmsbcg729_init();
50 #endif
51 #endif /*ANDROID*/
52
53 static JavaVM *jvm=0;
54 static const char* LogDomain = "Linphone";
55
56 #ifdef ANDROID
57 void linphone_android_log_handler(int prio, const char *fmt, va_list args) {
58         char str[4096];
59         char *current;
60         char *next;
61
62         vsnprintf(str, sizeof(str) - 1, fmt, args);
63         str[sizeof(str) - 1] = '\0';
64         if (strlen(str) < 512) {
65                 __android_log_write(prio, LogDomain, str);
66         } else {
67                 current = str;
68                 while ((next = strchr(current, '\n')) != NULL) {
69                         *next = '\0';
70                         __android_log_write(prio, LogDomain, current);
71                         current = next + 1;
72                 }
73                 __android_log_write(prio, LogDomain, current);
74         }
75 }
76
77 static void linphone_android_ortp_log_handler(OrtpLogLevel lev, const char *fmt, va_list args) {
78         int prio;
79         switch(lev){
80         case ORTP_DEBUG:        prio = ANDROID_LOG_DEBUG;       break;
81         case ORTP_MESSAGE:      prio = ANDROID_LOG_INFO;        break;
82         case ORTP_WARNING:      prio = ANDROID_LOG_WARN;        break;
83         case ORTP_ERROR:        prio = ANDROID_LOG_ERROR;       break;
84         case ORTP_FATAL:        prio = ANDROID_LOG_FATAL;       break;
85         default:                prio = ANDROID_LOG_DEFAULT;     break;
86         }
87         linphone_android_log_handler(prio, fmt, args);
88 }
89
90 int dumbMethodForAllowingUsageOfCpuFeaturesFromStaticLibMediastream() {
91         return (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
92 }
93 #endif /*ANDROID*/
94
95 JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
96 {
97 #ifdef ANDROID
98         ms_set_jvm(ajvm);
99 #endif /*ANDROID*/
100         jvm=ajvm;
101         return JNI_VERSION_1_2;
102 }
103
104
105 //LinphoneFactory
106 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
107                 ,jobject  thiz
108                 ,jboolean isDebug
109                 ,jstring  jdebugTag) {
110         if (isDebug) {
111                 LogDomain = env->GetStringUTFChars(jdebugTag, NULL);
112                 linphone_core_enable_logs_with_cb(linphone_android_ortp_log_handler);
113         } else {
114                 linphone_core_disable_logs();
115         }
116 }
117 // LinphoneCore
118
119 class LinphoneCoreData {
120 public:
121         LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {
122
123                 core = env->NewGlobalRef(lc);
124                 listener = env->NewGlobalRef(alistener);
125                 userdata = auserdata?env->NewGlobalRef(auserdata):0;
126                 memset(&vTable,0,sizeof(vTable));
127                 vTable.show = showInterfaceCb;
128                 vTable.auth_info_requested = authInfoRequested;
129                 vTable.display_status = displayStatusCb;
130                 vTable.display_message = displayMessageCb;
131                 vTable.display_warning = displayMessageCb;
132                 vTable.global_state_changed = globalStateChange;
133                 vTable.registration_state_changed = registrationStateChange;
134                 vTable.call_state_changed = callStateChange;
135                 vTable.call_encryption_changed = callEncryptionChange;
136                 vTable.text_received = text_received;
137                 vTable.message_received = message_received;
138                 vTable.dtmf_received = dtmf_received;
139                 vTable.new_subscription_request = new_subscription_request;
140                 vTable.notify_presence_recv = notify_presence_recv;
141                 vTable.call_stats_updated = callStatsUpdated;
142
143                 listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
144
145                 /*displayStatus(LinphoneCore lc,String message);*/
146                 displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
147
148                 /*void generalState(LinphoneCore lc,int state); */
149                 globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
150                 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
151                 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
152
153                 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
154                 registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
155                 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
156                 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
157
158                 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
159                 callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
160                 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
161                 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
162
163                 /*callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats);*/
164                 callStatsUpdatedId = env->GetMethodID(listenerClass, "callStatsUpdated", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCallStats;)V");
165
166                 chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State"));
167                 chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;");
168
169                 /*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
170                 callEncryptionChangedId=env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
171
172                 /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
173                 ecCalibrationStatusId = env->GetMethodID(listenerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
174                 ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
175                 ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
176
177                 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
178                 newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
179
180                 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
181                 notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
182
183                 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
184                 textReceivedId = env->GetMethodID(listenerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
185                 messageReceivedId = env->GetMethodID(listenerClass,"messageReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneChatMessage;)V");
186                 dtmfReceivedId = env->GetMethodID(listenerClass,"dtmfReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;I)V");
187
188                 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
189                 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
190
191                 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
192                 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
193
194                 chatMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessageImpl"));
195                 if (chatMessageClass) chatMessageCtrId = env->GetMethodID(chatMessageClass,"<init>", "(J)V");
196
197                 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
198                 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
199
200                 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
201                 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
202
203                 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
204                 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
205
206                 callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl"));
207                 callStatsId = env->GetMethodID(callStatsClass, "<init>", "(JJ)V");
208                 callSetAudioStatsId = env->GetMethodID(callClass, "setAudioStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
209                 callSetVideoStatsId = env->GetMethodID(callClass, "setVideoStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
210         }
211
212         ~LinphoneCoreData() {
213                 JNIEnv *env = 0;
214                 jvm->AttachCurrentThread(&env,NULL);
215                 env->DeleteGlobalRef(core);
216                 env->DeleteGlobalRef(listener);
217                 if (userdata) env->DeleteGlobalRef(userdata);
218                 env->DeleteGlobalRef(listenerClass);
219                 env->DeleteGlobalRef(globalStateClass);
220                 env->DeleteGlobalRef(registrationStateClass);
221                 env->DeleteGlobalRef(callStateClass);
222                 env->DeleteGlobalRef(callStatsClass);
223                 env->DeleteGlobalRef(chatMessageStateClass);
224                 env->DeleteGlobalRef(proxyClass);
225                 env->DeleteGlobalRef(callClass);
226                 env->DeleteGlobalRef(chatMessageClass);
227                 env->DeleteGlobalRef(chatRoomClass);
228                 env->DeleteGlobalRef(friendClass);
229
230         }
231         jobject core;
232         jobject listener;
233         jobject userdata;
234
235         jclass listenerClass;
236         jmethodID displayStatusId;
237         jmethodID newSubscriptionRequestId;
238         jmethodID notifyPresenceReceivedId;
239         jmethodID textReceivedId;
240         jmethodID messageReceivedId;
241         jmethodID dtmfReceivedId;
242         jmethodID callStatsUpdatedId;
243
244         jclass globalStateClass;
245         jmethodID globalStateId;
246         jmethodID globalStateFromIntId;
247
248         jclass registrationStateClass;
249         jmethodID registrationStateId;
250         jmethodID registrationStateFromIntId;
251
252         jclass callStateClass;
253         jmethodID callStateId;
254         jmethodID callStateFromIntId;
255
256         jclass callStatsClass;
257         jmethodID callStatsId;
258         jmethodID callSetAudioStatsId;
259         jmethodID callSetVideoStatsId;
260
261         jclass chatMessageStateClass;
262         jmethodID chatMessageStateFromIntId;
263
264         jmethodID callEncryptionChangedId;
265
266         jclass ecCalibratorStatusClass;
267         jmethodID ecCalibrationStatusId;
268         jmethodID ecCalibratorStatusFromIntId;
269
270         jclass proxyClass;
271         jmethodID proxyCtrId;
272
273         jclass callClass;
274         jmethodID callCtrId;
275
276         jclass chatMessageClass;
277         jmethodID chatMessageCtrId;
278
279         jclass chatRoomClass;
280         jmethodID chatRoomCtrId;
281
282         jclass friendClass;
283         jmethodID friendCtrId;
284
285         jclass addressClass;
286         jmethodID addressCtrId;
287
288         LinphoneCoreVTable vTable;
289
290         static void showInterfaceCb(LinphoneCore *lc) {
291
292         }
293         static void byeReceivedCb(LinphoneCore *lc, const char *from) {
294
295         }
296         static void displayStatusCb(LinphoneCore *lc, const char *message) {
297                 JNIEnv *env = 0;
298                 jint result = jvm->AttachCurrentThread(&env,NULL);
299                 if (result != 0) {
300                         ms_error("cannot attach VM\n");
301                         return;
302                 }
303                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
304                 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,message ? env->NewStringUTF(message) : NULL);
305         }
306         static void displayMessageCb(LinphoneCore *lc, const char *message) {
307
308         }
309         static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
310
311         }
312         static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
313                 JNIEnv *env = 0;
314                 jint result = jvm->AttachCurrentThread(&env,NULL);
315                 if (result != 0) {
316                         ms_error("cannot attach VM\n");
317                         return;
318                 }
319                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
320                 env->CallVoidMethod(lcData->listener
321                                                         ,lcData->globalStateId
322                                                         ,lcData->core
323                                                         ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
324                                                         message ? env->NewStringUTF(message) : NULL);
325         }
326         static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
327                 JNIEnv *env = 0;
328                 jint result = jvm->AttachCurrentThread(&env,NULL);
329                 if (result != 0) {
330                         ms_error("cannot attach VM\n");
331                         return;
332                 }
333                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
334                 env->CallVoidMethod(lcData->listener
335                                                         ,lcData->registrationStateId
336                                                         ,lcData->core
337                                                         ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
338                                                         ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
339                                                         message ? env->NewStringUTF(message) : NULL);
340         }
341         jobject getCall(JNIEnv *env , LinphoneCall *call){
342                 jobject jobj=0;
343
344                 if (call!=NULL){
345                         void *up=linphone_call_get_user_pointer(call);
346                         
347                         if (up==NULL){
348                                 jobj=env->NewObject(callClass,callCtrId,(jlong)call);
349                                 jobj=env->NewGlobalRef(jobj);
350                                 linphone_call_set_user_pointer(call,(void*)jobj);
351                                 linphone_call_ref(call);
352                         }else{
353                                 jobj=(jobject)up;
354                         }
355                 }
356                 return jobj;
357         }
358
359         static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
360                 JNIEnv *env = 0;
361                 jint result = jvm->AttachCurrentThread(&env,NULL);
362                 jobject jcall;
363                 if (result != 0) {
364                         ms_error("cannot attach VM\n");
365                         return;
366                 }
367                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
368                 env->CallVoidMethod(lcData->listener
369                                                         ,lcData->callStateId
370                                                         ,lcData->core
371                                                         ,(jcall=lcData->getCall(env,call))
372                                                         ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
373                                                         message ? env->NewStringUTF(message) : NULL);
374                 if (state==LinphoneCallReleased){
375                         linphone_call_set_user_pointer(call,NULL);
376                         env->DeleteGlobalRef(jcall);
377                 }
378         }
379         static void callEncryptionChange(LinphoneCore *lc, LinphoneCall* call, bool_t encrypted,const char* authentication_token) {
380                 JNIEnv *env = 0;
381                 jint result = jvm->AttachCurrentThread(&env,NULL);
382                 if (result != 0) {
383                         ms_error("cannot attach VM\n");
384                         return;
385                 }
386                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
387                 env->CallVoidMethod(lcData->listener
388                                                         ,lcData->callEncryptionChangedId
389                                                         ,lcData->core
390                                                         ,lcData->getCall(env,call)
391                                                         ,encrypted
392                                                         ,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
393         }
394         static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
395                 JNIEnv *env = 0;
396                 jint result = jvm->AttachCurrentThread(&env,NULL);
397                 if (result != 0) {
398                         ms_error("cannot attach VM\n");
399                         return;
400                 }
401                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
402                 env->CallVoidMethod(lcData->listener
403                                                         ,lcData->notifyPresenceReceivedId
404                                                         ,lcData->core
405                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
406         }
407         static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
408                 JNIEnv *env = 0;
409                 jint result = jvm->AttachCurrentThread(&env,NULL);
410                 if (result != 0) {
411                         ms_error("cannot attach VM\n");
412                         return;
413                 }
414                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
415                 env->CallVoidMethod(lcData->listener
416                                                         ,lcData->newSubscriptionRequestId
417                                                         ,lcData->core
418                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
419                                                         ,url ? env->NewStringUTF(url) : NULL);
420         }
421         static void dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf) {
422                 JNIEnv *env = 0;
423                 jint result = jvm->AttachCurrentThread(&env,NULL);
424                 if (result != 0) {
425                         ms_error("cannot attach VM\n");
426                         return;
427                 }
428                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
429                 env->CallVoidMethod(lcData->listener
430                                                         ,lcData->dtmfReceivedId
431                                                         ,lcData->core
432                                                         ,lcData->getCall(env,call)
433                                                         ,dtmf);
434         }
435         static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
436                 JNIEnv *env = 0;
437                 jint result = jvm->AttachCurrentThread(&env,NULL);
438                 if (result != 0) {
439                         ms_error("cannot attach VM\n");
440                         return;
441                 }
442                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
443                 env->CallVoidMethod(lcData->listener
444                                                         ,lcData->textReceivedId
445                                                         ,lcData->core
446                                                         ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
447                                                         ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
448                                                         ,message ? env->NewStringUTF(message) : NULL);
449         }
450         static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
451                         JNIEnv *env = 0;
452                         jint result = jvm->AttachCurrentThread(&env,NULL);
453                         if (result != 0) {
454                                 ms_error("cannot attach VM\n");
455                                 return;
456                         }
457                         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
458                         env->CallVoidMethod(lcData->listener
459                                                                 ,lcData->messageReceivedId
460                                                                 ,lcData->core
461                                                                 ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
462                                                                 ,env->NewObject(lcData->chatMessageClass,lcData->chatMessageCtrId,(jlong)msg));
463                 }
464         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
465                 JNIEnv *env = 0;
466                 jint result = jvm->AttachCurrentThread(&env,NULL);
467                 if (result != 0) {
468                         ms_error("cannot attach VM\n");
469                         return;
470                 }
471                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
472                 env->CallVoidMethod(lcData->listener
473                                                         ,lcData->ecCalibrationStatusId
474                                                         ,lcData->core
475                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
476                                                         ,delay_ms
477                                                         ,data ? data : NULL);
478                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
479                         //final state, releasing global ref
480                         env->DeleteGlobalRef((jobject)data);
481                 }
482
483         }
484         static void callStatsUpdated(LinphoneCore *lc, LinphoneCall* call, const LinphoneCallStats *stats) {
485                 JNIEnv *env = 0;
486                 jobject statsobj;
487                 jobject callobj;
488                 jint result = jvm->AttachCurrentThread(&env,NULL);
489                 if (result != 0) {
490                         ms_error("cannot attach VM\n");
491                         return;
492                 }
493                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
494                 statsobj = env->NewObject(lcData->callStatsClass, lcData->callStatsId, (jlong)call, (jlong)stats);
495                 callobj = lcData->getCall(env, call);
496                 if (stats->type == LINPHONE_CALL_STATS_AUDIO)
497                         env->CallVoidMethod(callobj, lcData->callSetAudioStatsId, statsobj);
498                 else
499                         env->CallVoidMethod(callobj, lcData->callSetVideoStatsId, statsobj);
500                 env->CallVoidMethod(lcData->listener, lcData->callStatsUpdatedId, lcData->core, callobj, statsobj);
501         }
502
503
504 };
505 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
506                 ,jobject  thiz
507                 ,jobject jlistener
508                 ,jstring juserConfig
509                 ,jstring jfactoryConfig
510                 ,jobject  juserdata){
511
512         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
513         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
514         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
515
516 #ifdef HAVE_ILBC
517         libmsilbc_init(); // requires an fpu
518 #endif
519 #ifdef HAVE_X264
520         libmsx264_init();
521 #endif
522 #ifdef HAVE_AMR
523         libmsamr_init();
524 #endif
525 #ifdef HAVE_SILK
526         libmssilk_init();
527 #endif
528 #ifdef HAVE_G729
529         libmsbcg729_init();
530 #endif
531         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
532                         ,userConfig
533                         ,factoryConfig
534                         ,ldata);
535
536         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
537         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
538         return nativePtr;
539 }
540 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
541                 ,jobject  thiz
542                 ,jlong lc) {
543         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
544         linphone_core_destroy((LinphoneCore*)lc);
545         delete lcData;
546 }
547
548 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPrimaryContact(JNIEnv* env, jobject  thiz, jlong lc, jstring jdisplayname, jstring jusername) {
549         const char* displayname = env->GetStringUTFChars(jdisplayname, NULL);
550         const char* username = env->GetStringUTFChars(jusername, NULL);
551
552         LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed((LinphoneCore*)lc);
553     if (parsed != NULL) {
554         linphone_address_set_display_name(parsed, displayname);
555         linphone_address_set_username(parsed, username);
556         char *contact = linphone_address_as_string(parsed);
557                 linphone_core_set_primary_contact((LinphoneCore*)lc, contact);
558         }
559
560         env->ReleaseStringUTFChars(jdisplayname, displayname);
561         env->ReleaseStringUTFChars(jusername, username);
562 }
563
564 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
565         linphone_core_clear_proxy_config((LinphoneCore*)lc);
566 }
567
568 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
569                 ,jobject  thiz
570                 ,jlong lc
571                 ,jlong pc) {
572         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
573 }
574 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
575                 ,jobject  thiz
576                 ,jlong lc) {
577         LinphoneProxyConfig *config=0;
578         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
579         return (jlong)config;
580 }
581
582 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigList(JNIEnv* env, jobject thiz, jlong lc) {
583         const MSList* proxies = linphone_core_get_proxy_config_list((LinphoneCore*)lc);
584         int proxyCount = ms_list_size(proxies);
585         jlongArray jProxies = env->NewLongArray(proxyCount);
586         jlong *jInternalArray = env->GetLongArrayElements(jProxies, NULL);
587
588         for (int i = 0; i < proxyCount; i++ ) {
589                 jInternalArray[i] = (unsigned long) (proxies->data);
590                 proxies = proxies->next;
591         }
592
593         env->ReleaseLongArrayElements(jProxies, jInternalArray, 0);
594
595         return jProxies;
596 }
597
598 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig( JNIEnv*  env
599                 ,jobject  thiz
600                 ,jobject jproxyCfg
601                 ,jlong lc
602                 ,jlong pc) {
603         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
604         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
605
606         return (jint)linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
607 }
608
609 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
610         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
611 }
612
613 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_refreshRegisters(JNIEnv* env, jobject thiz,jlong lc) {
614         linphone_core_refresh_registers((LinphoneCore*)lc);
615 }
616
617 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
618                 ,jobject  thiz
619                 ,jlong lc
620                 ,jlong pc) {
621         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
622 }
623 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
624                 ,jobject  thiz
625                 ,jlong lc) {
626         linphone_core_iterate((LinphoneCore*)lc);
627 }
628 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_invite(      JNIEnv*  env
629                 ,jobject  thiz
630                 ,jlong lc
631                 ,jstring juri) {
632         const char* uri = env->GetStringUTFChars(juri, NULL);
633         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
634         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
635         env->ReleaseStringUTFChars(juri, uri);
636         return lcd->getCall(env,lCall);
637 }
638 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddress(       JNIEnv*  env
639                 ,jobject  thiz
640                 ,jlong lc
641                 ,jlong to) {
642         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
643         return lcd->getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to));
644 }
645
646 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
647                 ,jobject  thiz
648                 ,jlong lc
649                 ,jlong call) {
650         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
651 }
652
653 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_declineCall(    JNIEnv*  env
654                 ,jobject  thiz
655                 ,jlong lc
656                 ,jlong call, jint reason) {
657         linphone_core_decline_call((LinphoneCore*)lc,(LinphoneCall*)call,(LinphoneReason)reason);
658 }
659
660 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
661                 ,jobject  thiz
662                 ,jlong lc) {
663         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
664 }
665 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
666                 ,jobject  thiz
667                 ,jlong lc) {
668
669         return (jboolean)linphone_core_in_call((LinphoneCore*)lc);
670 }
671 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
672                 ,jobject  thiz
673                 ,jlong lc) {
674
675         return (jboolean)linphone_core_inc_invite_pending((LinphoneCore*)lc);
676 }
677 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
678                 ,jobject  thiz
679                 ,jlong lc
680                 ,jlong call) {
681
682         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
683 }
684
685 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallWithParams(JNIEnv *env,
686                 jobject thiz,
687                 jlong lc,
688                 jlong call,
689                 jlong params){
690         linphone_core_accept_call_with_params((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
691 }
692
693 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallUpdate(JNIEnv *env,
694                 jobject thiz,
695                 jlong lc,
696                 jlong call,
697                 jlong params){
698         linphone_core_accept_call_update((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
699 }
700
701 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_deferCallUpdate(JNIEnv *env,
702                 jobject thiz,
703                 jlong lc,
704                 jlong call){
705         linphone_core_defer_call_update((LinphoneCore*)lc,(LinphoneCall*)call);
706 }
707
708 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
709                 ,jobject  thiz
710                 ,jlong lc
711                 ,jint position) {
712                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
713 }
714 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
715                 ,jobject  thiz
716                 ,jlong lc) {
717                 return (jint)ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
718 }
719 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
720                 ,jobject  thiz
721                 ,jlong lc
722                 ,jboolean isReachable) {
723                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
724 }
725
726 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isNetworkStateReachable(    JNIEnv*  env
727                 ,jobject  thiz
728                 ,jlong lc) {
729                 return (jboolean)linphone_core_is_network_reachable((LinphoneCore*)lc);
730 }
731
732 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMicrophoneGain(JNIEnv*  env
733                 ,jobject  thiz
734                 ,jlong lc
735                 ,jfloat gain) {
736                 linphone_core_set_mic_gain_db((LinphoneCore*)lc,gain);
737 }
738
739 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
740                 ,jobject  thiz
741                 ,jlong lc
742                 ,jfloat gain) {
743                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
744 }
745
746 extern "C" jfloat Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(      JNIEnv*  env
747                 ,jobject  thiz
748                 ,jlong lc) {
749                 return (jfloat)linphone_core_get_playback_gain_db((LinphoneCore*)lc);
750 }
751
752 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
753                 ,jobject  thiz
754                 ,jlong lc
755                 ,jboolean isMuted) {
756                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
757 }
758
759 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
760                 ,jobject  thiz
761                 ,jlong lc
762                 ,jstring jurl) {
763         const char* url = env->GetStringUTFChars(jurl, NULL);
764         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
765         env->ReleaseStringUTFChars(jurl, url);
766         return result;
767 }
768 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
769                 ,jobject  thiz
770                 ,jlong lc
771                 ,jchar dtmf) {
772         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
773 }
774 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
775                 ,jobject  thiz
776                 ,jlong lc
777                 ,jchar dtmf
778                 ,jint duration) {
779         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
780 }
781 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
782                 ,jobject  thiz
783                 ,jlong lc) {
784         linphone_core_stop_dtmf((LinphoneCore*)lc);
785 }
786
787 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMissedCallsCount(JNIEnv*  env
788                                                                                                                                                 ,jobject  thiz
789                                                                                                                                                 ,jlong lc) {
790         return (jint)linphone_core_get_missed_calls_count((LinphoneCore*)lc);
791 }
792
793 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_resetMissedCallsCount(JNIEnv*  env
794                                                                                                                                                 ,jobject  thiz
795                                                                                                                                                 ,jlong lc) {
796         linphone_core_reset_missed_calls_count((LinphoneCore*)lc);
797 }
798
799 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeCallLog(JNIEnv*  env
800                                                                                                                                                 ,jobject  thiz
801                                                                                                                                                 ,jlong lc, jlong log) {
802         linphone_core_remove_call_log((LinphoneCore*)lc, (LinphoneCallLog*) log);
803 }
804
805 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
806                                                                                                                                                 ,jobject  thiz
807                                                                                                                                                 ,jlong lc) {
808         linphone_core_clear_call_logs((LinphoneCore*)lc);
809 }
810 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
811                 ,jobject  thiz
812                 ,jlong lc) {
813         return (jboolean)linphone_core_is_mic_muted((LinphoneCore*)lc);
814 }
815 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
816                                                                                                                                                         ,jobject  thiz
817                                                                                                                                                         ,jlong lc
818                                                                                                                                                         ,jstring jmime
819                                                                                                                                                         ,jint rate
820                                                                                                                                                         ,jint channels) {
821         const char* mime = env->GetStringUTFChars(jmime, NULL);
822         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate,channels);
823         env->ReleaseStringUTFChars(jmime, mime);
824         return result;
825 }
826 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
827                                                                                                                                                         ,jobject  thiz
828                                                                                                                                                         ,jlong lc) {
829         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
830         int codecsCount = ms_list_size(codecs);
831         jlongArray jCodecs = env->NewLongArray(codecsCount);
832         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
833
834         for (int i = 0; i < codecsCount; i++ ) {
835                 jInternalArray[i] = (unsigned long) (codecs->data);
836                 codecs = codecs->next;
837         }
838
839         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
840
841         return jCodecs;
842 }
843
844 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
845                                                                                                                                                         ,jobject  thiz
846                                                                                                                                                         ,jlong lc) {
847         const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
848         int codecsCount = ms_list_size(codecs);
849         jlongArray jCodecs = env->NewLongArray(codecsCount);
850         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
851
852         for (int i = 0; i < codecsCount; i++ ) {
853                 jInternalArray[i] = (unsigned long) (codecs->data);
854                 codecs = codecs->next;
855         }
856
857         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
858
859         return jCodecs;
860 }
861
862 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
863                                                                                                                                                         ,jobject  thiz
864                                                                                                                                                         ,jlong lc
865                                                                                                                                                         ,jlong pt
866                                                                                                                                                         ,jboolean enable) {
867         return (jint)linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
868 }
869 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
870                                                                                                                                                         ,jobject  thiz
871                                                                                                                                                         ,jlong lc
872                                                                                                                                                         ,jboolean enable) {
873         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
874 }
875 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoLimiter(JNIEnv*  env
876                                                                                                                                                         ,jobject  thiz
877                                                                                                                                                         ,jlong lc
878                                                                                                                                                         ,jboolean enable) {
879         linphone_core_enable_echo_limiter((LinphoneCore*)lc,enable);
880 }
881 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
882                                                                                                                                                         ,jobject  thiz
883                                                                                                                                                         ,jlong lc
884                                                                                                                                                         ) {
885         return (jboolean)linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
886 }
887
888 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoLimiterEnabled(JNIEnv*  env
889                                                                                                                                                         ,jobject  thiz
890                                                                                                                                                         ,jlong lc
891                                                                                                                                                         ) {
892         return (jboolean)linphone_core_echo_limiter_enabled((LinphoneCore*)lc);
893 }
894
895 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
896                                                                                                                                                         ,jobject  thiz
897                                                                                                                                                         ,jlong lc
898                                                                                                                                                         ) {
899         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
900         
901         return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc));
902 }
903 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
904                                                                                                                                                         ,jobject  thiz
905                                                                                                                                                         ,jlong lc
906                                                                                                                                                         ,jlong aFriend
907                                                                                                                                                         ) {
908         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
909 }
910 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
911                                                                                                                                                         ,jobject  thiz
912                                                                                                                                                         ,jlong lc
913                                                                                                                                                         ,jint minute_away
914                                                                                                                                                         ,jstring jalternative_contact
915                                                                                                                                                         ,jint status) {
916         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
917         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
918         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
919 }
920
921 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
922                                                                                                                                                         ,jobject  thiz
923                                                                                                                                                         ,jlong lc
924                                                                                                                                                         ,jstring jto) {
925
926         const char* to = env->GetStringUTFChars(jto, NULL);
927         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
928         env->ReleaseStringUTFChars(jto, to);
929         return (jlong)lResult;
930 }
931
932 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
933                                                                                                                                                         ,jobject  thiz
934                                                                                                                                                         ,jlong lc
935                                                                                                                                                         ,jboolean vcap_enabled
936                                                                                                                                                         ,jboolean display_enabled) {
937         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
938
939 }
940 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
941                                                                                                                                                         ,jobject  thiz
942                                                                                                                                                         ,jlong lc) {
943         return (jboolean)linphone_core_video_enabled((LinphoneCore*)lc);
944 }
945 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlayFile(JNIEnv*  env
946                                                                                                                                                         ,jobject  thiz
947                                                                                                                                                         ,jlong lc
948                                                                                                                                                         ,jstring jpath) {
949         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
950         linphone_core_set_play_file((LinphoneCore*)lc,path);
951         if (path) env->ReleaseStringUTFChars(jpath, path);
952 }
953 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
954                                                                                                                                                         ,jobject  thiz
955                                                                                                                                                         ,jlong lc
956                                                                                                                                                         ,jstring jpath) {
957         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
958         linphone_core_set_ring((LinphoneCore*)lc,path);
959         if (path) env->ReleaseStringUTFChars(jpath, path);
960 }
961 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
962                                                                                                                                                         ,jobject  thiz
963                                                                                                                                                         ,jlong lc
964                                                                                                                                                         ) {
965         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
966         if (path) {
967                 return env->NewStringUTF(path);
968         } else {
969                 return NULL;
970         }
971 }
972 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRootCA(JNIEnv*  env
973                                                                                                                                                         ,jobject  thiz
974                                                                                                                                                         ,jlong lc
975                                                                                                                                                         ,jstring jpath) {
976         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
977         linphone_core_set_root_ca((LinphoneCore*)lc,path);
978         if (path) env->ReleaseStringUTFChars(jpath, path);
979 }
980 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
981                                                                                                                                 ,jobject  thiz
982                                                                                                                                 ,jlong lc
983                                                                                                                                 ,jboolean enable) {
984         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
985
986 }
987 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
988                                                                                                                                 ,jobject  thiz
989                                                                                                                                 ,jlong lc) {
990         return (jboolean)linphone_core_keep_alive_enabled((LinphoneCore*)lc);
991
992 }
993 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
994                                                                                                                                                                 ,jobject  thiz
995                                                                                                                                                                 ,jlong lc
996                                                                                                                                                                 ,jobject data) {
997         return (jint)linphone_core_start_echo_calibration((LinphoneCore*)lc
998                                                                                                         , LinphoneCoreData::ecCalibrationStatus
999                                                                                                         , NULL
1000                                                                                                         , NULL
1001                                                                                                         , data?env->NewGlobalRef(data):NULL);
1002
1003 }
1004
1005 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_needsEchoCalibration(JNIEnv *env, jobject thiz, jlong lc){
1006         MSSndCard *sndcard;
1007         MSSndCardManager *m=ms_snd_card_manager_get();
1008         const char *card=linphone_core_get_capture_device((LinphoneCore*)lc);
1009         sndcard=ms_snd_card_manager_get_card(m,card);
1010         if (sndcard == NULL){
1011                 ms_error("Could not get soundcard.");
1012                 return TRUE;
1013         }
1014         return (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER) || (ms_snd_card_get_minimal_latency(sndcard)>0);
1015 }
1016
1017 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryption(JNIEnv*  env
1018                                                                                                                                                         ,jobject  thiz
1019                                                                                                                                                         ,jlong lc
1020                                                                                                                                                         ) {
1021         return (jint)linphone_core_get_media_encryption((LinphoneCore*)lc);
1022 }
1023
1024 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryption(JNIEnv*  env
1025                                                                                                                                                         ,jobject  thiz
1026                                                                                                                                                         ,jlong lc
1027                                                                                                                                                         ,jint menc) {
1028         linphone_core_set_media_encryption((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
1029 }
1030
1031 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_mediaEncryptionSupported(JNIEnv*  env
1032                                                                                                                                                         ,jobject  thiz
1033                                                                                                                                                         ,jlong lc, jint menc
1034                                                                                                                                                         ) {
1035         return (jboolean)linphone_core_media_encryption_supported((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
1036 }
1037
1038 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMediaEncryptionMandatory(JNIEnv*  env
1039                                                                                                                                                         ,jobject  thiz
1040                                                                                                                                                         ,jlong lc
1041                                                                                                                                                         ) {
1042         return (jboolean)linphone_core_is_media_encryption_mandatory((LinphoneCore*)lc);
1043 }
1044
1045 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryptionMandatory(JNIEnv*  env
1046                                                                                                                                                         ,jobject  thiz
1047                                                                                                                                                         ,jlong lc
1048                                                                                                                                                         , jboolean yesno
1049                                                                                                                                                         ) {
1050         linphone_core_set_media_encryption_mandatory((LinphoneCore*)lc, yesno);
1051 }
1052
1053 //ProxyConfig
1054
1055 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
1056         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
1057         return  (jlong) proxy;
1058 }
1059
1060 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
1061         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
1062 }
1063 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
1064         const char* identity = env->GetStringUTFChars(jidentity, NULL);
1065         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
1066         env->ReleaseStringUTFChars(jidentity, identity);
1067 }
1068 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1069         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
1070         if (identity) {
1071                 return env->NewStringUTF(identity);
1072         } else {
1073                 return NULL;
1074         }
1075 }
1076 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
1077         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
1078         jint err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
1079         env->ReleaseStringUTFChars(jproxy, proxy);
1080         return err;
1081 }
1082 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1083         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
1084         if (proxy) {
1085                 return env->NewStringUTF(proxy);
1086         } else {
1087                 return NULL;
1088         }
1089 }
1090 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setContactParameters(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jparams) {
1091         const char* params = env->GetStringUTFChars(jparams, NULL);
1092         linphone_proxy_config_set_contact_parameters((LinphoneProxyConfig*)proxyCfg, params);
1093         env->ReleaseStringUTFChars(jparams, params);
1094 }
1095 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
1096         if (jroute != NULL) {
1097                 const char* route = env->GetStringUTFChars(jroute, NULL);
1098                 jint err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
1099                 env->ReleaseStringUTFChars(jroute, route);
1100                 return err;
1101         } else {
1102                 return (jint)linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
1103         }
1104 }
1105 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1106         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
1107         if (route) {
1108                 return env->NewStringUTF(route);
1109         } else {
1110                 return NULL;
1111         }
1112 }
1113
1114 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
1115         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
1116 }
1117 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1118         return (jboolean)linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
1119 }
1120 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1121         return (jboolean)linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
1122 }
1123 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1124         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
1125 }
1126 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1127         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
1128 }
1129 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
1130         if (jnumber == 0) {
1131                 ms_error("cannot normalized null number");
1132         }
1133         const char* number = env->GetStringUTFChars(jnumber, NULL);
1134         int len = env->GetStringLength(jnumber);
1135         if (len == 0) {
1136                 ms_warning("cannot normalize empty number");
1137                 return jnumber;
1138         }
1139         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
1140         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
1141         jstring normalizedNumber = env->NewStringUTF(targetBuff);
1142         env->ReleaseStringUTFChars(jnumber, number);
1143         return normalizedNumber;
1144 }
1145 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_lookupCCCFromIso(JNIEnv* env, jobject thiz, jlong proxyCfg, jstring jiso) {
1146         const char* iso = env->GetStringUTFChars(jiso, NULL);
1147         int prefix = linphone_dial_plan_lookup_ccc_from_iso(iso);
1148         env->ReleaseStringUTFChars(jiso, iso);
1149         return (jint) prefix;
1150 }
1151 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_lookupCCCFromE164(JNIEnv* env, jobject thiz, jlong proxyCfg, jstring je164) {
1152         const char* e164 = env->GetStringUTFChars(je164, NULL);
1153         int prefix = linphone_dial_plan_lookup_ccc_from_e164(e164);
1154         env->ReleaseStringUTFChars(je164, e164);
1155         return (jint) prefix;
1156 }
1157 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
1158                                                                                                                                                         ,jobject thiz
1159                                                                                                                                                         ,jlong proxyCfg) {
1160         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
1161         if (domain) {
1162                 return env->NewStringUTF(domain);
1163         } else {
1164                 return NULL;
1165         }
1166 }
1167 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
1168         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
1169 }
1170
1171 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
1172                                                                                                                                         ,jobject thiz
1173                                                                                                                                         ,jlong proxyCfg
1174                                                                                                                                         ,jstring jprefix) {
1175         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
1176         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
1177         env->ReleaseStringUTFChars(jprefix, prefix);
1178 }
1179 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
1180                                                                                                                                                                 ,jobject thiz
1181                                                                                                                                                                 ,jlong proxyCfg
1182                                                                                                                                                                 ,jboolean val) {
1183         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
1184 }
1185 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1186         return (jboolean)linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
1187 }
1188
1189 //Auth Info
1190
1191 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
1192                 , jobject thiz ) {
1193         return (jlong)linphone_auth_info_new(NULL,NULL,NULL,NULL,NULL);
1194 }
1195 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
1196                 , jobject thiz
1197                 , jlong ptr) {
1198         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
1199 }
1200 /*
1201  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1202  * Method:    getPassword
1203  * Signature: (J)Ljava/lang/String;
1204  */
1205 JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getPassword
1206 (JNIEnv *env , jobject, jlong auth_info) {
1207         const char* passwd = linphone_auth_info_get_passwd((LinphoneAuthInfo*)auth_info);
1208         if (passwd) {
1209                 return env->NewStringUTF(passwd);
1210         } else {
1211                 return NULL;
1212         }
1213
1214 }
1215 /*
1216  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1217  * Method:    getRealm
1218  * Signature: (J)Ljava/lang/String;
1219  */
1220 JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getRealm
1221 (JNIEnv *env , jobject, jlong auth_info) {
1222         const char* realm = linphone_auth_info_get_realm((LinphoneAuthInfo*)auth_info);
1223         if (realm) {
1224                 return env->NewStringUTF(realm);
1225         } else {
1226                 return NULL;
1227         }
1228
1229 }
1230
1231 /*
1232  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1233  * Method:    getUsername
1234  * Signature: (J)Ljava/lang/String;
1235  */
1236 JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getUsername
1237 (JNIEnv *env , jobject, jlong auth_info) {
1238         const char* username = linphone_auth_info_get_username((LinphoneAuthInfo*)auth_info);
1239         if (username) {
1240                 return env->NewStringUTF(username);
1241         } else {
1242                 return NULL;
1243         }
1244 }
1245
1246 /*
1247  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1248  * Method:    setPassword
1249  * Signature: (JLjava/lang/String;)V
1250  */
1251 JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setPassword
1252 (JNIEnv *env, jobject, jlong auth_info, jstring jpassword) {
1253         const char* password = jpassword?env->GetStringUTFChars(jpassword, NULL):NULL;
1254         linphone_auth_info_set_passwd((LinphoneAuthInfo*)auth_info,password);
1255         if (password) env->ReleaseStringUTFChars(jpassword, password);
1256 }
1257
1258 /*
1259  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1260  * Method:    setRealm
1261  * Signature: (JLjava/lang/String;)V
1262  */
1263 JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setRealm
1264 (JNIEnv *env, jobject, jlong auth_info, jstring jrealm) {
1265         const char* realm = jrealm?env->GetStringUTFChars(jrealm, NULL):NULL;
1266         linphone_auth_info_set_realm((LinphoneAuthInfo*)auth_info,realm);
1267         if (realm) env->ReleaseStringUTFChars(jrealm, realm);
1268 }
1269 /*
1270  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1271  * Method:    setUsername
1272  * Signature: (JLjava/lang/String;)V
1273  */
1274 JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setUsername
1275 (JNIEnv *env, jobject, jlong auth_info, jstring jusername) {
1276         const char* username = jusername?env->GetStringUTFChars(jusername, NULL):NULL;
1277         linphone_auth_info_set_username((LinphoneAuthInfo*)auth_info,username);
1278         if (username) env->ReleaseStringUTFChars(jusername, username);
1279 }
1280
1281 /*
1282  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1283  * Method:    setAuthUserId
1284  * Signature: (JLjava/lang/String;)V
1285  */
1286 JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setUserId
1287 (JNIEnv *env, jobject, jlong auth_info, jstring juserid) {
1288         const char* userid = juserid?env->GetStringUTFChars(juserid, NULL):NULL;
1289         linphone_auth_info_set_userid((LinphoneAuthInfo*)auth_info,userid);
1290         if (userid) env->ReleaseStringUTFChars(juserid, userid);
1291 }
1292
1293 /*
1294  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1295  * Method:    getAuthUserId
1296  * Signature: (J)Ljava/lang/String;
1297  */
1298 JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getUserId
1299 (JNIEnv *env , jobject, jlong auth_info) {
1300         const char* userid = linphone_auth_info_get_userid((LinphoneAuthInfo*)auth_info);
1301         if (userid) {
1302                 return env->NewStringUTF(userid);
1303         } else {
1304                 return NULL;
1305         }
1306 }
1307
1308 /*
1309  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1310  * Method:    setHa1
1311  * Signature: (JLjava/lang/String;)V
1312  */
1313 JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setHa1
1314 (JNIEnv *env, jobject, jlong auth_info, jstring jha1) {
1315         const char* ha1 = jha1?env->GetStringUTFChars(jha1, NULL):NULL;
1316         linphone_auth_info_set_ha1((LinphoneAuthInfo*)auth_info,ha1);
1317         if (ha1) env->ReleaseStringUTFChars(jha1, ha1);
1318 }
1319
1320
1321 /*
1322  * Class:     org_linphone_core_LinphoneAuthInfoImpl
1323  * Method:    getHa1
1324  * Signature: (J)Ljava/lang/String;
1325  */
1326 JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getHa1
1327 (JNIEnv *env , jobject, jlong auth_info) {
1328         const char* ha1 = linphone_auth_info_get_ha1((LinphoneAuthInfo*)auth_info);
1329         if (ha1) {
1330                 return env->NewStringUTF(ha1);
1331         } else {
1332                 return NULL;
1333         }
1334 }
1335
1336
1337 //LinphoneAddress
1338
1339 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
1340                                                                                                                                                                         ,jobject  thiz
1341                                                                                                                                                                         ,jstring juri
1342                                                                                                                                                                         ,jstring jdisplayName) {
1343         const char* uri = env->GetStringUTFChars(juri, NULL);
1344         LinphoneAddress* address = linphone_address_new(uri);
1345         if (jdisplayName && address) {
1346                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
1347                 linphone_address_set_display_name(address,displayName);
1348                 env->ReleaseStringUTFChars(jdisplayName, displayName);
1349         }
1350         env->ReleaseStringUTFChars(juri, uri);
1351
1352         return  (jlong) address;
1353 }
1354 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
1355                                                                                                                                                 ,jobject  thiz
1356                                                                                                                                                 ,jlong ptr) {
1357         linphone_address_destroy((LinphoneAddress*)ptr);
1358 }
1359
1360 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
1361                                                                                                                                                 ,jobject  thiz
1362                                                                                                                                                 ,jlong ptr) {
1363         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
1364         if (displayName) {
1365                 return env->NewStringUTF(displayName);
1366         } else {
1367                 return NULL;
1368         }
1369 }
1370 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
1371                                                                                                                                                 ,jobject  thiz
1372                                                                                                                                                 ,jlong ptr) {
1373         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
1374         if (userName) {
1375                 return env->NewStringUTF(userName);
1376         } else {
1377                 return NULL;
1378         }
1379 }
1380 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
1381                                                                                                                                                 ,jobject  thiz
1382                                                                                                                                                 ,jlong ptr) {
1383         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
1384         if (domain) {
1385                 return env->NewStringUTF(domain);
1386         } else {
1387                 return NULL;
1388         }
1389 }
1390
1391 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
1392                                                                                                                                                 ,jobject  thiz
1393                                                                                                                                                 ,jlong ptr) {
1394         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
1395         jstring juri =env->NewStringUTF(uri);
1396         ms_free(uri);
1397         return juri;
1398 }
1399 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
1400                                                                                                                                                 ,jobject  thiz
1401                                                                                                                                                 ,jlong ptr) {
1402         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
1403         jstring juri =env->NewStringUTF(uri);
1404         ms_free(uri);
1405         return juri;
1406 }
1407 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
1408                                                                                                                                                 ,jobject  thiz
1409                                                                                                                                                 ,jlong address
1410                                                                                                                                                 ,jstring jdisplayName) {
1411         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
1412         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
1413         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
1414 }
1415
1416
1417 //CallLog
1418 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
1419                                                                                                                                                 ,jobject  thiz
1420                                                                                                                                                 ,jlong ptr) {
1421         return (jlong)((LinphoneCallLog*)ptr)->from;
1422 }
1423 extern "C" jint Java_org_linphone_core_LinphoneCallLogImpl_getStatus(JNIEnv*  env
1424                                                                                                                                                 ,jobject  thiz
1425                                                                                                                                                 ,jlong ptr) {
1426         return (jint)((LinphoneCallLog*)ptr)->status;
1427 }
1428 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
1429                                                                                                                                                 ,jobject  thiz
1430                                                                                                                                                 ,jlong ptr) {
1431         return (jlong)((LinphoneCallLog*)ptr)->to;
1432 }
1433 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
1434                                                                                                                                                 ,jobject  thiz
1435                                                                                                                                                 ,jlong ptr) {
1436         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1437 }
1438 extern "C" jstring Java_org_linphone_core_LinphoneCallLogImpl_getStartDate(JNIEnv*  env
1439                                                                                                                                                 ,jobject  thiz
1440                                                                                                                                                 ,jlong ptr) {
1441         jstring jvalue =env->NewStringUTF(((LinphoneCallLog*)ptr)->start_date);
1442         return jvalue;
1443 }
1444 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTimestamp(JNIEnv*  env
1445                                                                                                                                                 ,jobject  thiz
1446                                                                                                                                                 ,jlong ptr) {
1447         return static_cast<long> (((LinphoneCallLog*)ptr)->start_date_time);
1448 }
1449 extern "C" jint Java_org_linphone_core_LinphoneCallLogImpl_getCallDuration(JNIEnv*  env
1450                                                                                                                                                 ,jobject  thiz
1451                                                                                                                                                 ,jlong ptr) {
1452         return (jint)((LinphoneCallLog*)ptr)->duration;
1453 }
1454
1455 /* CallStats */
1456 extern "C" jint Java_org_linphone_core_LinphoneCallStatsImpl_getMediaType(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1457         return (jint)((LinphoneCallStats *)stats_ptr)->type;
1458 }
1459 extern "C" jint Java_org_linphone_core_LinphoneCallStatsImpl_getIceState(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1460         return (jint)((LinphoneCallStats *)stats_ptr)->ice_state;
1461 }
1462 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getDownloadBandwidth(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1463         return (jfloat)((LinphoneCallStats *)stats_ptr)->download_bandwidth;
1464 }
1465 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getUploadBandwidth(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1466         return (jfloat)((LinphoneCallStats *)stats_ptr)->upload_bandwidth;
1467 }
1468 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderLossRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1469         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1470         const report_block_t *srb = NULL;
1471
1472         if (!stats || !stats->sent_rtcp)
1473                 return (jfloat)0.0;
1474         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1475         if (stats->sent_rtcp->b_cont != NULL)
1476                 msgpullup(stats->sent_rtcp, -1);
1477         if (rtcp_is_SR(stats->sent_rtcp))
1478                 srb = rtcp_SR_get_report_block(stats->sent_rtcp, 0);
1479         else if (rtcp_is_RR(stats->sent_rtcp))
1480                 srb = rtcp_RR_get_report_block(stats->sent_rtcp, 0);
1481         if (!srb)
1482                 return (jfloat)0.0;
1483         return (jfloat)(100.0 * report_block_get_fraction_lost(srb) / 256.0);
1484 }
1485 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverLossRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1486         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1487         const report_block_t *rrb = NULL;
1488
1489         if (!stats || !stats->received_rtcp)
1490                 return (jfloat)0.0;
1491         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1492         if (stats->received_rtcp->b_cont != NULL)
1493                 msgpullup(stats->received_rtcp, -1);
1494         if (rtcp_is_RR(stats->received_rtcp))
1495                 rrb = rtcp_RR_get_report_block(stats->received_rtcp, 0);
1496         else if (rtcp_is_SR(stats->received_rtcp))
1497                 rrb = rtcp_SR_get_report_block(stats->received_rtcp, 0);
1498         if (!rrb)
1499                 return (jfloat)0.0;
1500         return (jfloat)(100.0 * report_block_get_fraction_lost(rrb) / 256.0);
1501 }
1502 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1503         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1504         LinphoneCall *call = (LinphoneCall *)call_ptr;
1505         const LinphoneCallParams *params;
1506         const PayloadType *pt;
1507         const report_block_t *srb = NULL;
1508
1509         if (!stats || !call || !stats->sent_rtcp)
1510                 return (jfloat)0.0;
1511         params = linphone_call_get_current_params(call);
1512         if (!params)
1513                 return (jfloat)0.0;
1514         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1515         if (stats->sent_rtcp->b_cont != NULL)
1516                 msgpullup(stats->sent_rtcp, -1);
1517         if (rtcp_is_SR(stats->sent_rtcp))
1518                 srb = rtcp_SR_get_report_block(stats->sent_rtcp, 0);
1519         else if (rtcp_is_RR(stats->sent_rtcp))
1520                 srb = rtcp_RR_get_report_block(stats->sent_rtcp, 0);
1521         if (!srb)
1522                 return (jfloat)0.0;
1523         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1524                 pt = linphone_call_params_get_used_audio_codec(params);
1525         else
1526                 pt = linphone_call_params_get_used_video_codec(params);
1527         if (!pt || (pt->clock_rate == 0))
1528                 return (jfloat)0.0;
1529         return (jfloat)((float)report_block_get_interarrival_jitter(srb) / (float)pt->clock_rate);
1530 }
1531 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1532         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1533         LinphoneCall *call = (LinphoneCall *)call_ptr;
1534         const LinphoneCallParams *params;
1535         const PayloadType *pt;
1536         const report_block_t *rrb = NULL;
1537
1538         if (!stats || !call || !stats->received_rtcp)
1539                 return (jfloat)0.0;
1540         params = linphone_call_get_current_params(call);
1541         if (!params)
1542                 return (jfloat)0.0;
1543         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1544         if (stats->received_rtcp->b_cont != NULL)
1545                 msgpullup(stats->received_rtcp, -1);
1546         if (rtcp_is_SR(stats->received_rtcp))
1547                 rrb = rtcp_SR_get_report_block(stats->received_rtcp, 0);
1548         else if (rtcp_is_RR(stats->received_rtcp))
1549                 rrb = rtcp_RR_get_report_block(stats->received_rtcp, 0);
1550         if (!rrb)
1551                 return (jfloat)0.0;
1552         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1553                 pt = linphone_call_params_get_used_audio_codec(params);
1554         else
1555                 pt = linphone_call_params_get_used_video_codec(params);
1556         if (!pt || (pt->clock_rate == 0))
1557                 return (jfloat)0.0;
1558         return (jfloat)((float)report_block_get_interarrival_jitter(rrb) / (float)pt->clock_rate);
1559 }
1560 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getRoundTripDelay(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1561         return (jfloat)((LinphoneCallStats *)stats_ptr)->round_trip_delay;
1562 }
1563 extern "C" jlong Java_org_linphone_core_LinphoneCallStatsImpl_getLatePacketsCumulativeNumber(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1564         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1565         LinphoneCall *call = (LinphoneCall *)call_ptr;
1566         rtp_stats_t rtp_stats;
1567
1568         if (!stats || !call)
1569                 return (jlong)0;
1570         memset(&rtp_stats, 0, sizeof(rtp_stats));
1571         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1572                 audio_stream_get_local_rtp_stats(call->audiostream, &rtp_stats);
1573 #ifdef VIDEO_ENABLED
1574         else
1575                 video_stream_get_local_rtp_stats(call->videostream, &rtp_stats);
1576 #endif
1577         return (jlong)rtp_stats.outoftime;
1578 }
1579 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getJitterBufferSize(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1580         return (jfloat)((LinphoneCallStats *)stats_ptr)->jitter_stats.jitter_buffer_size_ms;
1581 }
1582
1583 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getLocalLossRate(JNIEnv *env, jobject thiz,jlong stats_ptr) {
1584         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1585         return stats->local_loss_rate;
1586 }
1587
1588 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getLocalLateRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1589         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1590         return stats->local_late_rate;
1591 }
1592
1593 extern "C" void Java_org_linphone_core_LinphoneCallStatsImpl_updateStats(JNIEnv *env, jobject thiz, jlong call_ptr, jint mediatype) {
1594         if (mediatype==LINPHONE_CALL_STATS_AUDIO)
1595                 linphone_call_get_audio_stats((LinphoneCall*)call_ptr);
1596         else 
1597                 linphone_call_get_video_stats((LinphoneCall*)call_ptr);
1598 }
1599
1600 /*payloadType*/
1601 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
1602         PayloadType* pt = (PayloadType*)ptr;
1603         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
1604                                                                         ,payload_type_get_mime(pt)
1605                                                                         ,payload_type_get_rate(pt)
1606                                                                         ,payload_type_get_bitrate(pt));
1607         jstring jvalue =env->NewStringUTF(value);
1608         ms_free(value);
1609         return jvalue;
1610 }
1611 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
1612         PayloadType* pt = (PayloadType*)ptr;
1613         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
1614         return jvalue;
1615 }
1616 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
1617         PayloadType* pt = (PayloadType*)ptr;
1618         return (jint)payload_type_get_rate(pt);
1619 }
1620
1621 //LinphoneCall
1622 extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv*  env
1623                                                                                                                                                 ,jobject  thiz
1624                                                                                                                                                 ,jlong ptr) {
1625         LinphoneCall *call=(LinphoneCall*)ptr;
1626         linphone_call_unref(call);
1627 }
1628
1629 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1630                                                                                                                                                 ,jobject  thiz
1631                                                                                                                                                 ,jlong ptr) {
1632         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1633 }
1634
1635 extern "C" void Java_org_linphone_core_LinphoneCallImpl_takeSnapshot(   JNIEnv*  env
1636                                                                                                                                                 ,jobject  thiz
1637                                                                                                                                                 ,jlong ptr, jstring path) {
1638         const char* filePath = path != NULL ? env->GetStringUTFChars(path, NULL) : NULL;
1639         linphone_call_take_video_snapshot((LinphoneCall*)ptr, filePath);
1640 }
1641
1642 extern "C" void Java_org_linphone_core_LinphoneCallImpl_zoomVideo(              JNIEnv*  env
1643                                                                                                                                                 ,jobject  thiz
1644                                                                                                                                                 ,jlong ptr, jfloat zoomFactor, jfloat cx, jfloat cy) {
1645         linphone_call_zoom_video((LinphoneCall*)ptr, zoomFactor, &cx, &cy);
1646 }
1647
1648 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1649                                                                                                                                                 ,jobject  thiz
1650                                                                                                                                                 ,jlong ptr) {
1651         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1652 }
1653
1654 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1655                                                                                                                                                 ,jobject  thiz
1656                                                                                                                                                 ,jlong ptr) {
1657         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1658 }
1659
1660 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getRemoteUserAgent(JNIEnv *env, jobject thiz, jlong ptr) {
1661         LinphoneCall *call = (LinphoneCall *)ptr;
1662         const char *value=linphone_call_get_remote_user_agent(call);
1663         jstring jvalue=NULL;
1664         if (value) jvalue=env->NewStringUTF(value);
1665         return jvalue;
1666 }
1667
1668 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getRemoteContact(JNIEnv *env, jobject thiz, jlong ptr) {
1669         LinphoneCall *call = (LinphoneCall *)ptr;
1670         const char *value=linphone_call_get_remote_contact(call);
1671         jstring jvalue = NULL;
1672         if (value) jvalue=env->NewStringUTF(value);
1673         return jvalue;
1674 }
1675
1676 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1677                                                                                                                                                 ,jobject  thiz
1678                                                                                                                                                 ,jlong ptr) {
1679         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1680 }
1681 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1682                                                                                                                                                 ,jobject  thiz
1683                                                                                                                                                 ,jlong ptr
1684                                                                                                                                                 ,jboolean value) {
1685         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1686 }
1687 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1688                                                                                                                                                 ,jobject  thiz
1689                                                                                                                                                 ,jlong ptr) {
1690         return (jboolean)linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1691 }
1692
1693 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1694                                                                                                                                                 ,jobject  thiz
1695                                                                                                                                                 ,jlong ptr
1696                                                                                                                                                 ,jboolean value) {
1697         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1698 }
1699 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1700                                                                                                                                                 ,jobject  thiz
1701                                                                                                                                                 ,jlong ptr) {
1702         return (jboolean)linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1703 }
1704
1705 extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(     JNIEnv*  env
1706                                                                                                                                                 ,jobject  thiz
1707                                                                                                                                                 ,jlong ptr) {
1708         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(linphone_call_get_core((LinphoneCall*)ptr));       
1709         return lcd->getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr));
1710 }
1711
1712 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1713                                                                                                                                                 ,jobject  thiz
1714                                                                                                                                                 ,jlong ptr) {
1715         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1716 }
1717
1718 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1719                                                                                                                                                 ,jobject  thiz
1720                                                                                                                                                 ,jlong ptr) {
1721         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1722 }
1723
1724 //LinphoneFriend
1725 extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1726                                                                                                                                                 ,jobject  thiz
1727                                                                                                                                                 ,jstring jFriendUri) {
1728         LinphoneFriend* lResult;
1729
1730         if (jFriendUri) {
1731                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1732                 lResult= linphone_friend_new_with_addr(friendUri);
1733                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1734         } else {
1735                 lResult = linphone_friend_new();
1736         }
1737         return (jlong)lResult;
1738 }
1739 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1740                                                                                                                                                 ,jobject  thiz
1741                                                                                                                                                 ,jlong ptr
1742                                                                                                                                                 ,jlong linphoneAddress) {
1743         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1744 }
1745 extern "C" jlong Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1746                                                                                                                                                 ,jobject  thiz
1747                                                                                                                                                 ,jlong ptr) {
1748         return (jlong)linphone_friend_get_address((LinphoneFriend*)ptr);
1749 }
1750 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1751                                                                                                                                                 ,jobject  thiz
1752                                                                                                                                                 ,jlong ptr
1753                                                                                                                                                 ,jint policy) {
1754         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1755 }
1756 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1757                                                                                                                                                 ,jobject  thiz
1758                                                                                                                                                 ,jlong ptr) {
1759         return (jint)linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1760 }
1761 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1762                                                                                                                                                 ,jobject  thiz
1763                                                                                                                                                 ,jlong ptr
1764                                                                                                                                                 ,jboolean value) {
1765         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1766 }
1767 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1768                                                                                                                                                 ,jobject  thiz
1769                                                                                                                                                 ,jlong ptr) {
1770         return (jboolean)linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1771 }
1772 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1773                                                                                                                                                 ,jobject  thiz
1774                                                                                                                                                 ,jlong ptr) {
1775         return (jint)linphone_friend_get_status((LinphoneFriend*)ptr);
1776 }
1777 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1778                                                                                                                                                 ,jobject  thiz
1779                                                                                                                                                 ,jlong ptr) {
1780         return linphone_friend_edit((LinphoneFriend*)ptr);
1781 }
1782 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1783                                                                                                                                                 ,jobject  thiz
1784                                                                                                                                                 ,jlong ptr) {
1785          linphone_friend_done((LinphoneFriend*)ptr);
1786 }
1787 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFriend(JNIEnv*  env
1788                                                                                                                                                 ,jobject  thiz
1789                                                                                                                                                 ,jlong ptr
1790                                                                                                                                                 ,jlong lf) {
1791         linphone_core_remove_friend((LinphoneCore*)ptr, (LinphoneFriend*)lf);
1792 }
1793 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getFriendByAddress(JNIEnv*  env
1794                                                                                                                                                 ,jobject  thiz
1795                                                                                                                                                 ,jlong ptr
1796                                                                                                                                                 ,jstring jaddress) {
1797         const char* address = env->GetStringUTFChars(jaddress, NULL);
1798         LinphoneFriend *lf = linphone_core_get_friend_by_address((LinphoneCore*)ptr, address);
1799         env->ReleaseStringUTFChars(jaddress, address);
1800         return (jlong) lf;
1801 }
1802 //LinphoneChatRoom
1803 extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1804                                                                                                                                                 ,jobject  thiz
1805                                                                                                                                                 ,jlong ptr) {
1806         return (jlong) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1807 }
1808 extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage(JNIEnv*  env
1809                                                                                                                                                 ,jobject  thiz
1810                                                                                                                                                 ,jlong ptr
1811                                                                                                                                                 ,jstring jmessage) {
1812         const char* message = env->GetStringUTFChars(jmessage, NULL);
1813         LinphoneChatMessage *chatMessage = linphone_chat_room_create_message((LinphoneChatRoom *)ptr, message);
1814         env->ReleaseStringUTFChars(jmessage, message);
1815
1816         return (jlong) chatMessage;
1817 }
1818 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setUserData(JNIEnv*  env
1819                                                                                                                                                 ,jobject  thiz
1820                                                                                                                                                 ,jlong ptr) {
1821         jobject ud = env->NewGlobalRef(thiz);
1822         linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr,(void*) ud);
1823 }
1824 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getText(JNIEnv*  env
1825                                                                                                                                                 ,jobject  thiz
1826                                                                                                                                                 ,jlong ptr) {
1827         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_text((LinphoneChatMessage*)ptr));
1828         return jvalue;
1829 }
1830
1831 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getCustomHeader(JNIEnv*  env
1832                                                                                                                                                 ,jobject  thiz
1833                                                                                                                                                 ,jlong ptr, jstring jheader_name) {
1834         const char *name=env->GetStringUTFChars(jheader_name,NULL);
1835         const char *value=linphone_chat_message_get_custom_header((LinphoneChatMessage*)ptr,name);
1836         env->ReleaseStringUTFChars(jheader_name, name);
1837         return value ? env->NewStringUTF(value) : NULL;
1838 }
1839
1840 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_addCustomHeader(JNIEnv*  env
1841                                                                                                                                                 ,jobject  thiz
1842                                                                                                                                                 ,jlong ptr, jstring jheader_name, jstring jheader_value) {
1843         const char *name=env->GetStringUTFChars(jheader_name,NULL);
1844         const char *value=env->GetStringUTFChars(jheader_value,NULL);
1845         linphone_chat_message_add_custom_header((LinphoneChatMessage*)ptr,name,value);
1846         env->ReleaseStringUTFChars(jheader_name, name);
1847         env->ReleaseStringUTFChars(jheader_value, value);
1848 }
1849
1850 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getExternalBodyUrl(JNIEnv*  env
1851                                                                                                                                                 ,jobject  thiz
1852                                                                                                                                                 ,jlong ptr) {
1853         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_external_body_url((LinphoneChatMessage*)ptr));
1854         return jvalue;
1855 }
1856 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setExternalBodyUrl(JNIEnv*  env
1857                                                                                                                                                 ,jobject  thiz
1858                                                                                                                                                 ,jlong ptr
1859                                                                                                                                                 ,jstring jurl) {
1860         const char* url = env->GetStringUTFChars(jurl, NULL);
1861         linphone_chat_message_set_external_body_url((LinphoneChatMessage *)ptr, url);
1862         env->ReleaseStringUTFChars(jurl, url);
1863 }
1864 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getFrom(JNIEnv*  env
1865                                                                                                                                                 ,jobject  thiz
1866                                                                                                                                                 ,jlong ptr) {
1867         return (jlong) linphone_chat_message_get_from((LinphoneChatMessage*)ptr);
1868 }
1869
1870 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getPeerAddress(JNIEnv*  env
1871                                                                                                                                                 ,jobject  thiz
1872                                                                                                                                                 ,jlong ptr) {
1873         return (jlong) linphone_chat_message_get_peer_address((LinphoneChatMessage*)ptr);
1874 }
1875
1876 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getTime(JNIEnv*  env
1877                                                                                                                                                 ,jobject  thiz
1878                                                                                                                                                 ,jlong ptr) {
1879         return (jlong) linphone_chat_message_get_time((LinphoneChatMessage*)ptr);
1880 }
1881
1882 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1883                                                                                                                                                 ,jobject  thiz
1884                                                                                                                                                 ,jlong ptr
1885                                                                                                                                                 ,jstring jmessage) {
1886         const char* message = env->GetStringUTFChars(jmessage, NULL);
1887         linphone_chat_room_send_message((LinphoneChatRoom*)ptr, message);
1888         env->ReleaseStringUTFChars(jmessage, message);
1889 }
1890
1891 static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessageState state, void* ud) {
1892         JNIEnv *env = 0;
1893         jint result = jvm->AttachCurrentThread(&env,NULL);
1894         if (result != 0) {
1895                 ms_error("cannot attach VM\n");
1896                 return;
1897         }
1898
1899         jobject listener = (jobject) ud;
1900         jclass clazz = (jclass) env->GetObjectClass(listener);
1901         jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
1902
1903         LinphoneCore *lc = linphone_chat_room_get_lc(linphone_chat_message_get_chat_room(msg));
1904         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
1905         env->CallVoidMethod(
1906                         listener,
1907                         method,
1908                         (jobject)linphone_chat_message_get_user_data(msg),
1909                         env->CallStaticObjectMethod(lcData->chatMessageStateClass,lcData->chatMessageStateFromIntId,(jint)state));
1910
1911         if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) {
1912                 env->DeleteGlobalRef(listener);
1913         }
1914 }
1915 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv*  env
1916                                                                                                                                                 ,jobject  thiz
1917                                                                                                                                                 ,jlong ptr
1918                                                                                                                                                 ,jlong jmessage
1919                                                                                                                                                 ,jobject jlistener) {
1920         jobject listener = env->NewGlobalRef(jlistener);
1921         linphone_chat_room_send_message2((LinphoneChatRoom*)ptr, (LinphoneChatMessage*)jmessage, chat_room_impl_callback, (void*)listener);
1922 }
1923 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1924                                                                                                                                                 ,jobject thiz
1925                                                                                                                                                 ,jlong lc
1926                                                                                                                                                 ,jobject obj) {
1927         jobject oldWindow = (jobject) linphone_core_get_native_video_window_id((LinphoneCore*)lc);
1928         if (oldWindow != NULL) {
1929                 env->DeleteGlobalRef(oldWindow);
1930         }
1931         if (obj != NULL) {
1932                 obj = env->NewGlobalRef(obj);
1933         }
1934         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1935 }
1936
1937 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreviewWindowId(JNIEnv* env
1938                                                                                                                                                 ,jobject thiz
1939                                                                                                                                                 ,jlong lc
1940                                                                                                                                                 ,jobject obj) {
1941         jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id((LinphoneCore*)lc);
1942         if (oldWindow != NULL) {
1943                 env->DeleteGlobalRef(oldWindow);
1944         }
1945         if (obj != NULL) {
1946                 obj = env->NewGlobalRef(obj);
1947         }
1948         linphone_core_set_native_preview_window_id((LinphoneCore*)lc,(unsigned long)obj);
1949 }
1950
1951 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDeviceRotation(JNIEnv* env
1952                                                                                                                                                 ,jobject thiz
1953                                                                                                                                                 ,jlong lc
1954                                                                                                                                                 ,jint rotation) {
1955         linphone_core_set_device_rotation((LinphoneCore*)lc,rotation);
1956 }
1957
1958
1959 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, jint enum_value){
1960         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1961 }
1962
1963 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1964         return (jint)linphone_core_get_firewall_policy((LinphoneCore*)lc);
1965 }
1966
1967 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1968         const char* server = NULL;
1969         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1970         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1971         if (server) env->ReleaseStringUTFChars(jserver,server);
1972 }
1973
1974 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1975         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1976         if (ret==NULL) return NULL;
1977         jstring jvalue =env->NewStringUTF(ret);
1978         return jvalue;
1979 }
1980
1981 //CallParams
1982 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_isLowBandwidthEnabled(JNIEnv *env, jobject thiz, jlong cp) {
1983         return (jboolean) linphone_call_params_low_bandwidth_enabled((LinphoneCallParams *)cp);
1984 }
1985
1986 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableLowBandwidth(JNIEnv *env, jobject thiz, jlong cp, jboolean enable) {
1987         linphone_call_params_enable_low_bandwidth((LinphoneCallParams *)cp, enable);
1988 }
1989
1990 extern "C" jlong Java_org_linphone_core_LinphoneCallParamsImpl_getUsedAudioCodec(JNIEnv *env, jobject thiz, jlong cp) {
1991         return (jlong)linphone_call_params_get_used_audio_codec((LinphoneCallParams *)cp);
1992 }
1993
1994 extern "C" jlong Java_org_linphone_core_LinphoneCallParamsImpl_getUsedVideoCodec(JNIEnv *env, jobject thiz, jlong cp) {
1995         return (jlong)linphone_call_params_get_used_video_codec((LinphoneCallParams *)cp);
1996 }
1997
1998 extern "C" jint Java_org_linphone_core_LinphoneCallParamsImpl_getMediaEncryption(JNIEnv*  env
1999                                                                                                                                                         ,jobject  thiz
2000                                                                                                                                                         ,jlong cp
2001                                                                                                                                                         ) {
2002         return (jint)linphone_call_params_get_media_encryption((LinphoneCallParams*)cp);
2003 }
2004
2005 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setMediaEncryption(JNIEnv*  env
2006                                                                                                                                                         ,jobject  thiz
2007                                                                                                                                                         ,jlong cp
2008                                                                                                                                                         ,jint jmenc) {
2009         linphone_call_params_set_media_encryption((LinphoneCallParams*)cp,(LinphoneMediaEncryption)jmenc);
2010 }
2011
2012 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
2013         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
2014 }
2015
2016 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
2017         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
2018 }
2019
2020 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
2021         return (jboolean)linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
2022 }
2023
2024 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_localConferenceMode(JNIEnv *env, jobject thiz, jlong lcp){
2025         return (jboolean)linphone_call_params_local_conference_mode((LinphoneCallParams*)lcp);
2026 }
2027
2028 extern "C" jstring Java_org_linphone_core_LinphoneCallParamsImpl_getCustomHeader(JNIEnv *env, jobject thiz, jlong lcp, jstring jheader_name){
2029         const char* header_name=env->GetStringUTFChars(jheader_name, NULL);
2030         const char *header_value=linphone_call_params_get_custom_header((LinphoneCallParams*)lcp,header_name);
2031         env->ReleaseStringUTFChars(jheader_name, header_name);
2032         return header_value ? env->NewStringUTF(header_value) : NULL;
2033 }
2034
2035 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_addCustomHeader(JNIEnv *env, jobject thiz, jlong lcp, jstring jheader_name, jstring jheader_value){
2036         const char* header_name=env->GetStringUTFChars(jheader_name, NULL);
2037         const char* header_value=env->GetStringUTFChars(jheader_value, NULL);
2038         linphone_call_params_add_custom_header((LinphoneCallParams*)lcp,header_name,header_value);
2039         env->ReleaseStringUTFChars(jheader_name, header_name);
2040         env->ReleaseStringUTFChars(jheader_value, header_value);
2041 }
2042
2043 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setRecordFile(JNIEnv *env, jobject thiz, jlong lcp, jstring jrecord_file){
2044         if (jrecord_file){
2045                 const char* record_file=env->GetStringUTFChars(jrecord_file, NULL);
2046                 linphone_call_params_set_record_file((LinphoneCallParams*)lcp,record_file);
2047                 env->ReleaseStringUTFChars(jrecord_file, record_file);
2048         }else linphone_call_params_set_record_file((LinphoneCallParams*)lcp,NULL);
2049 }
2050
2051 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
2052         return linphone_call_params_destroy((LinphoneCallParams*)lc);
2053 }
2054 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
2055         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
2056 }
2057
2058 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteParams(JNIEnv *env, jobject thiz, jlong lc){
2059         if (linphone_call_get_remote_params((LinphoneCall*)lc) == NULL) {
2060                         return (jlong) 0;
2061         }
2062         return (jlong) linphone_call_params_copy(linphone_call_get_remote_params((LinphoneCall*)lc));
2063 }
2064
2065 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
2066         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
2067 }
2068
2069 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
2070         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
2071 }
2072
2073 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_cameraEnabled(JNIEnv *env, jobject thiz, jlong lc){
2074         return (jboolean)linphone_call_camera_enabled((LinphoneCall *)lc);
2075 }
2076
2077 extern "C" void Java_org_linphone_core_LinphoneCallImpl_startRecording(JNIEnv *env, jobject thiz, jlong lc){
2078         linphone_call_start_recording((LinphoneCall *)lc);
2079 }
2080
2081 extern "C" void Java_org_linphone_core_LinphoneCallImpl_stopRecording(JNIEnv *env, jobject thiz, jlong lc){
2082         linphone_call_stop_recording((LinphoneCall *)lc);
2083 }
2084
2085 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
2086         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
2087         return  lcd->getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params));
2088 }
2089
2090 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
2091         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
2092 }
2093
2094 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
2095         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
2096 }
2097
2098 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
2099         MSVideoSize vsize;
2100         vsize.width = (int)width;
2101         vsize.height = (int)height;
2102         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
2103 }
2104
2105 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
2106         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
2107     jintArray arr = env->NewIntArray(2);
2108         int tVsize [2]= {vsize.width,vsize.height};
2109     env->SetIntArrayRegion(arr, 0, 2, tVsize);
2110     return arr;
2111 }
2112
2113 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
2114         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
2115 }
2116
2117 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
2118         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
2119 }
2120
2121 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUseSipInfoForDtmfs(JNIEnv *env, jobject thiz, jlong lc, jboolean use){
2122         linphone_core_set_use_info_for_dtmf((LinphoneCore *)lc, (bool) use);
2123 }
2124
2125 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUseRfc2833ForDtmfs(JNIEnv *env, jobject thiz, jlong lc, jboolean use){
2126         linphone_core_set_use_rfc2833_for_dtmf((LinphoneCore *)lc, (bool) use);
2127 }
2128
2129 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
2130         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
2131 }
2132
2133 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
2134         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
2135 }
2136
2137 extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
2138         return (jint) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
2139 }
2140 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
2141         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
2142 }
2143
2144 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
2145         return (jint)linphone_call_get_duration((LinphoneCall *) ptr);
2146 }
2147
2148 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSipDscp(JNIEnv* env,jobject thiz,jlong ptr, jint dscp){
2149         linphone_core_set_sip_dscp((LinphoneCore*)ptr,dscp);
2150 }
2151
2152 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSipDscp(JNIEnv* env,jobject thiz,jlong ptr){
2153         return linphone_core_get_sip_dscp((LinphoneCore*)ptr);
2154 }
2155
2156 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
2157         LCSipTransports tr;
2158         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
2159                 switch (code) {
2160         case 0:
2161                 return tr.udp_port;
2162         case 1:
2163                 return tr.tcp_port;
2164         case 3:
2165                 return tr.tls_port;
2166         default:
2167                 return -2;
2168         }
2169 }
2170
2171 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
2172         LinphoneCore *lc = (LinphoneCore *) ptr;
2173         LCSipTransports tr;
2174         tr.udp_port = udp;
2175         tr.tcp_port = tcp;
2176         tr.tls_port = tls;
2177
2178         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
2179 }
2180
2181 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
2182               ,jlong lc, jboolean enable) {
2183               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
2184 }
2185
2186 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
2187               ,jlong ptr, jint db) {
2188         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
2189 }
2190
2191 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
2192         return (jint)linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
2193 }
2194 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
2195         return (jint)linphone_core_pause_all_calls((LinphoneCore *) pCore);
2196 }
2197 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
2198         return (jint)linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
2199 }
2200 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInConference(JNIEnv *env,jobject thiz,jlong pCore) {
2201         return (jboolean)linphone_core_is_in_conference((LinphoneCore *) pCore);
2202 }
2203 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_enterConference(JNIEnv *env,jobject thiz,jlong pCore) {
2204         return (jboolean)(0 == linphone_core_enter_conference((LinphoneCore *) pCore));
2205 }
2206 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_leaveConference(JNIEnv *env,jobject thiz,jlong pCore) {
2207         linphone_core_leave_conference((LinphoneCore *) pCore);
2208 }
2209 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAllToConference(JNIEnv *env,jobject thiz,jlong pCore) {
2210         linphone_core_add_all_to_conference((LinphoneCore *) pCore);
2211 }
2212
2213 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addToConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
2214         linphone_core_add_to_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
2215 }
2216
2217 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFromConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
2218         linphone_core_remove_from_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
2219 }
2220
2221 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateConference(JNIEnv *env,jobject thiz,jlong pCore) {
2222         linphone_core_terminate_conference((LinphoneCore *) pCore);
2223 }
2224 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv *env,jobject thiz,jlong pCore) {
2225         return (jint)linphone_core_get_conference_size((LinphoneCore *) pCore);
2226 }
2227
2228 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startConferenceRecording(JNIEnv *env,jobject thiz,jlong pCore, jstring jpath){
2229         int err=-1;
2230         if (jpath){
2231                 const char *path=env->GetStringUTFChars(jpath, NULL);
2232                 err=linphone_core_start_conference_recording((LinphoneCore*)pCore,path);
2233                 env->ReleaseStringUTFChars(jpath,path);
2234         }
2235         return err;
2236 }
2237
2238 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_stopConferenceRecording(JNIEnv *env,jobject thiz,jlong pCore){
2239         int err=linphone_core_stop_conference_recording((LinphoneCore*)pCore);
2240         return err;
2241 }
2242
2243 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
2244         linphone_core_terminate_all_calls((LinphoneCore *) pCore);
2245 }
2246 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) {
2247         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
2248         LinphoneCall* lCall = (LinphoneCall*) ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position);
2249         return lcd->getCall(env,lCall);
2250 }
2251 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) {
2252         return (jint)ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore));
2253 }
2254
2255 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_transferCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jstring jReferTo) {
2256         const char* cReferTo=env->GetStringUTFChars(jReferTo, NULL);
2257         jint err = linphone_core_transfer_call((LinphoneCore *) pCore, (LinphoneCall *) pCall, cReferTo);
2258         env->ReleaseStringUTFChars(jReferTo, cReferTo);
2259         return err;
2260 }
2261 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jlong pDestCall) {
2262         return (jint)linphone_core_transfer_call_to_another((LinphoneCore *) pCore, (LinphoneCall *) pCall, (LinphoneCall *) pDestCall);
2263 }
2264
2265 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
2266         if (jFile) {
2267                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
2268                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
2269                 env->ReleaseStringUTFChars(jFile, cFile);
2270         } else {
2271                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
2272         }
2273 }
2274
2275 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_findCallFromUri(JNIEnv *env,jobject thiz,jlong pCore, jstring jUri) {
2276         const char* cUri=env->GetStringUTFChars(jUri, NULL);
2277         LinphoneCall *call= (LinphoneCall *) linphone_core_find_call_from_uri((LinphoneCore *) pCore,cUri);
2278         env->ReleaseStringUTFChars(jUri, cUri);
2279         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
2280         return (jobject) lcdata->getCall(env,call);
2281 }
2282
2283
2284 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_setVideoDevice(JNIEnv *env,jobject thiz,jlong pCore,jint id) {
2285         LinphoneCore* lc = (LinphoneCore *) pCore;
2286         const char** devices = linphone_core_get_video_devices(lc);
2287         if (devices == NULL) {
2288                 ms_error("No existing video devices\n");
2289                 return -1;
2290         }
2291         int i;
2292         for(i=0; i<=id; i++) {
2293                 if (devices[i] == NULL)
2294                         break;
2295                 ms_message("Existing device %d : %s\n", i, devices[i]);
2296                 if (i==id) {
2297                         return (jint)linphone_core_set_video_device(lc, devices[i]);
2298                 }
2299         }
2300         return -1;
2301 }
2302
2303 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDevice(JNIEnv *env,jobject thiz,jlong pCore) {
2304         LinphoneCore* lc = (LinphoneCore *) pCore;
2305         const char** devices = linphone_core_get_video_devices(lc);
2306         if (devices == NULL) {
2307                 ms_error("No existing video devices\n");
2308                 return -1;
2309         }
2310         const char* cam = linphone_core_get_video_device(lc);
2311         if (cam == NULL) {
2312                 ms_error("No current video device\n");
2313         } else {
2314                 int i=0;
2315                 while(devices[i] != NULL) {
2316                         if (strcmp(devices[i], cam) == 0)
2317                                 return i;
2318                         i++;
2319                 }
2320         }
2321         ms_warning("Returning default (0) device\n");
2322         return 0;
2323 }
2324
2325 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
2326         LinphoneCall *call = (LinphoneCall *) ptr;
2327         const char* token = linphone_call_get_authentication_token(call);
2328         if (token == NULL) return NULL;
2329         return env->NewStringUTF(token);
2330 }
2331 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
2332         LinphoneCall *call = (LinphoneCall *) ptr;
2333         return (jboolean)linphone_call_get_authentication_token_verified(call);
2334 }
2335 extern "C" void Java_org_linphone_core_LinphoneCallImpl_setAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr,jboolean verified) {
2336         LinphoneCall *call = (LinphoneCall *) ptr;
2337         linphone_call_set_authentication_token_verified(call, verified);
2338 }
2339
2340 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getPlayVolume(JNIEnv* env, jobject thiz, jlong ptr) {
2341         LinphoneCall *call = (LinphoneCall *) ptr;
2342         return (jfloat)linphone_call_get_play_volume(call);
2343 }
2344
2345 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_soundResourcesLocked(JNIEnv* env,jobject thiz,jlong ptr){
2346         return (jboolean)linphone_core_sound_resources_locked((LinphoneCore *) ptr);
2347 }
2348
2349 // Needed by Galaxy S (can't switch to/from speaker while playing and still keep mic working)
2350 // Implemented directly in msandroid.cpp (sound filters for Android).
2351 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_forceSpeakerState(JNIEnv *env, jobject thiz, jlong ptr, jboolean speakerOn) {
2352         LinphoneCore *lc = (LinphoneCore *)ptr;
2353         LinphoneCall *call = linphone_core_get_current_call(lc);
2354         if (call && call->audiostream && call->audiostream->soundread) {
2355                 bool_t on = speakerOn;
2356                 ms_filter_call_method(call->audiostream->soundread, MS_AUDIO_CAPTURE_FORCE_SPEAKER_STATE, &on);
2357         }
2358 }
2359 // End Galaxy S hack functions
2360
2361
2362 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMaxCalls(JNIEnv *env,jobject thiz,jlong pCore) {
2363         return (jint) linphone_core_get_max_calls((LinphoneCore *) pCore);
2364 }
2365 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMaxCalls(JNIEnv *env,jobject thiz,jlong pCore, jint max) {
2366         linphone_core_set_max_calls((LinphoneCore *) pCore, (int) max);
2367 }
2368
2369 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror(JNIEnv *env,jobject thiz,jlong pCore,
2370                 jstring jHost, jint port, jint mirror, jint delay) {
2371         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
2372         if (!tunnel) return;
2373
2374         const char* cHost=env->GetStringUTFChars(jHost, NULL);
2375         LinphoneTunnelConfig *tunnelconfig = linphone_tunnel_config_new();
2376         linphone_tunnel_config_set_host(tunnelconfig, cHost);
2377         linphone_tunnel_config_set_port(tunnelconfig, port);
2378         linphone_tunnel_config_set_delay(tunnelconfig, delay);
2379         linphone_tunnel_config_set_remote_udp_mirror_port(tunnelconfig, mirror);
2380         linphone_tunnel_add_server(tunnel, tunnelconfig);
2381         env->ReleaseStringUTFChars(jHost, cHost);
2382 }
2383
2384 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelSetHttpProxy(JNIEnv *env,jobject thiz,jlong pCore,
2385                 jstring jHost, jint port, jstring username, jstring password) {
2386
2387         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
2388         if (!tunnel) return;
2389         const char* cHost=(jHost!=NULL) ? env->GetStringUTFChars(jHost, NULL) : NULL;
2390         const char* cUsername= (username!=NULL) ? env->GetStringUTFChars(username, NULL) : NULL;
2391         const char* cPassword= (password!=NULL) ? env->GetStringUTFChars(password, NULL) : NULL;
2392         linphone_tunnel_set_http_proxy(tunnel,cHost, port,cUsername,cPassword);
2393         if (cHost) env->ReleaseStringUTFChars(jHost, cHost);
2394         if (cUsername) env->ReleaseStringUTFChars(username, cUsername);
2395         if (cPassword) env->ReleaseStringUTFChars(password, cPassword);
2396 }
2397
2398
2399 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAutoDetect(JNIEnv *env,jobject thiz,jlong pCore) {
2400         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2401         linphone_tunnel_auto_detect(tunnel);
2402 }
2403
2404 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelCleanServers(JNIEnv *env,jobject thiz,jlong pCore) {
2405         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2406         linphone_tunnel_clean_servers(tunnel);
2407 }
2408
2409 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnable(JNIEnv *env,jobject thiz,jlong pCore, jboolean enable) {
2410         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2411         linphone_tunnel_enable(tunnel, enable);
2412 }
2413
2414
2415 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUserAgent(JNIEnv *env,jobject thiz,jlong pCore, jstring name, jstring version){
2416         const char* cname=env->GetStringUTFChars(name, NULL);
2417         const char* cversion=env->GetStringUTFChars(version, NULL);
2418         linphone_core_set_user_agent((LinphoneCore *)pCore,cname,cversion);
2419         env->ReleaseStringUTFChars(name, cname);
2420         env->ReleaseStringUTFChars(version, cversion);
2421 }
2422
2423 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isTunnelAvailable(JNIEnv *env,jobject thiz){
2424         return (jboolean)linphone_core_tunnel_available();
2425 }
2426
2427 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPolicy(JNIEnv *env, jobject thiz, jlong lc, jboolean autoInitiate, jboolean autoAccept){
2428         LinphoneVideoPolicy vpol;
2429         vpol.automatically_initiate = autoInitiate;
2430         vpol.automatically_accept = autoAccept;
2431         linphone_core_set_video_policy((LinphoneCore *)lc, &vpol);
2432 }
2433
2434 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStaticPicture(JNIEnv *env, jobject thiz, jlong lc, jstring path) {
2435         const char *cpath = env->GetStringUTFChars(path, NULL);
2436         linphone_core_set_static_picture((LinphoneCore *)lc, cpath);
2437         env->ReleaseStringUTFChars(path, cpath);
2438 }
2439
2440 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCpuCountNative(JNIEnv *env, jobject thiz, jint count) {
2441         ms_set_cpu_count(count);
2442 }
2443
2444 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setAudioPort(JNIEnv *env, jobject thiz, jlong lc, jint port) {
2445         linphone_core_set_audio_port((LinphoneCore *)lc, port);
2446 }
2447
2448 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPort(JNIEnv *env, jobject thiz, jlong lc, jint port) {
2449         linphone_core_set_video_port((LinphoneCore *)lc, port);
2450 }
2451
2452 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setAudioPortRange(JNIEnv *env, jobject thiz, jlong lc, jint min_port, jint max_port) {
2453         linphone_core_set_audio_port_range((LinphoneCore *)lc, min_port, max_port);
2454 }
2455
2456 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPortRange(JNIEnv *env, jobject thiz, jlong lc, jint min_port, jint max_port) {
2457         linphone_core_set_video_port_range((LinphoneCore *)lc, min_port, max_port);
2458 }
2459
2460 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setAudioDscp(JNIEnv* env,jobject thiz,jlong ptr, jint dscp){
2461         linphone_core_set_audio_dscp((LinphoneCore*)ptr,dscp);
2462 }
2463
2464 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getAudioDscp(JNIEnv* env,jobject thiz,jlong ptr){
2465         return linphone_core_get_audio_dscp((LinphoneCore*)ptr);
2466 }
2467
2468 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoDscp(JNIEnv* env,jobject thiz,jlong ptr, jint dscp){
2469         linphone_core_set_video_dscp((LinphoneCore*)ptr,dscp);
2470 }
2471
2472 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDscp(JNIEnv* env,jobject thiz,jlong ptr){
2473         return linphone_core_get_video_dscp((LinphoneCore*)ptr);
2474 }
2475
2476 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setIncomingTimeout(JNIEnv *env, jobject thiz, jlong lc, jint timeout) {
2477         linphone_core_set_inc_timeout((LinphoneCore *)lc, timeout);
2478 }
2479
2480 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setInCallTimeout(JNIEnv *env, jobject thiz, jlong lc, jint timeout) {
2481         linphone_core_set_in_call_timeout((LinphoneCore *)lc, timeout);
2482 }
2483
2484 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getVersion(JNIEnv*  env,jobject  thiz,jlong ptr) {
2485         jstring jvalue =env->NewStringUTF(linphone_core_get_version());
2486         return jvalue;
2487 }
2488
2489 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getConfig(JNIEnv *env, jobject thiz, jlong lc) {
2490         return (jlong) linphone_core_get_config((LinphoneCore *)lc);
2491 }
2492
2493 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_upnpAvailable(JNIEnv *env, jobject thiz, jlong lc) {
2494         return (jboolean) linphone_core_upnp_available((LinphoneCore *)lc);
2495 }
2496
2497 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getUpnpState(JNIEnv *env, jobject thiz, jlong lc) {
2498         return (jint) linphone_core_get_upnp_state((LinphoneCore *)lc);
2499 }
2500
2501 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getUpnpExternalIpaddress(JNIEnv *env, jobject thiz, jlong lc) {
2502         jstring jvalue = env->NewStringUTF(linphone_core_get_upnp_external_ipaddress((LinphoneCore *)lc));
2503         return jvalue;
2504 }
2505
2506 extern "C" jlong Java_org_linphone_core_LpConfigImpl_newLpConfigImpl(JNIEnv *env, jobject thiz, jstring file) {
2507         const char *cfile = env->GetStringUTFChars(file, NULL);
2508         LpConfig *lp = lp_config_new(cfile);
2509         env->ReleaseStringUTFChars(file, cfile);
2510         return (jlong) lp;
2511 }
2512
2513 extern "C" void Java_org_linphone_core_LpConfigImpl_sync(JNIEnv *env, jobject thiz, jlong lpc) {
2514         LpConfig *lp = (LpConfig *)lpc;
2515         lp_config_sync(lp);
2516 }
2517
2518 extern "C" void Java_org_linphone_core_LpConfigImpl_delete(JNIEnv *env, jobject thiz, jlong lpc) {
2519         LpConfig *lp = (LpConfig *)lpc;
2520         lp_config_destroy(lp);
2521 }
2522
2523 extern "C" void Java_org_linphone_core_LpConfigImpl_setInt(JNIEnv *env, jobject thiz, jlong lpc,
2524                 jstring section, jstring key, jint value) {
2525         const char *csection = env->GetStringUTFChars(section, NULL);
2526         const char *ckey = env->GetStringUTFChars(key, NULL);
2527         lp_config_set_int((LpConfig *)lpc, csection, ckey, (int) value);
2528         env->ReleaseStringUTFChars(section, csection);
2529         env->ReleaseStringUTFChars(key, ckey);
2530 }
2531