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