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