]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
Add JNI to access call statistics.
[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" int Java_org_linphone_core_LinphoneCallParamsImpl_getMediaEncryption(JNIEnv*  env
950                                                                                                                                                         ,jobject  thiz
951                                                                                                                                                         ,jlong cp
952                                                                                                                                                         ) {
953         return (int)linphone_call_params_get_media_encryption((LinphoneCallParams*)cp);
954 }
955
956 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_mediaEncryptionSupported(JNIEnv*  env
957                                                                                                                                                         ,jobject  thiz
958                                                                                                                                                         ,jlong lc, jint menc
959                                                                                                                                                         ) {
960         return linphone_core_media_encryption_supported((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
961 }
962
963 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setMediaEncryption(JNIEnv*  env
964                                                                                                                                                         ,jobject  thiz
965                                                                                                                                                         ,jlong cp
966                                                                                                                                                         ,int jmenc) {
967         linphone_call_params_set_media_encryption((LinphoneCallParams*)cp,(LinphoneMediaEncryption)jmenc);
968 }
969
970 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryptionMandatory(JNIEnv*  env
971                                                                                                                                                         ,jobject  thiz
972                                                                                                                                                         ,jlong lc
973                                                                                                                                                         ) {
974         return linphone_core_is_media_encryption_mandatory((LinphoneCore*)lc);
975 }
976
977 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryptionMandatory(JNIEnv*  env
978                                                                                                                                                         ,jobject  thiz
979                                                                                                                                                         ,jlong lc
980                                                                                                                                                         , jboolean yesno
981                                                                                                                                                         ) {
982         linphone_core_set_media_encryption_mandatory((LinphoneCore*)lc, yesno);
983 }
984
985 //ProxyConfig
986
987 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
988         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
989         return  (jlong) proxy;
990 }
991
992 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
993         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
994 }
995 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
996         const char* identity = env->GetStringUTFChars(jidentity, NULL);
997         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
998         env->ReleaseStringUTFChars(jidentity, identity);
999 }
1000 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1001         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
1002         if (identity) {
1003                 return env->NewStringUTF(identity);
1004         } else {
1005                 return NULL;
1006         }
1007 }
1008 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
1009         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
1010         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
1011         env->ReleaseStringUTFChars(jproxy, proxy);
1012         return err;
1013 }
1014 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1015         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
1016         if (proxy) {
1017                 return env->NewStringUTF(proxy);
1018         } else {
1019                 return NULL;
1020         }
1021 }
1022 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setContactParameters(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jparams) {
1023         const char* params = env->GetStringUTFChars(jparams, NULL);
1024         linphone_proxy_config_set_contact_parameters((LinphoneProxyConfig*)proxyCfg, params);
1025         env->ReleaseStringUTFChars(jparams, params);
1026 }
1027 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
1028         if (jroute != NULL) {
1029                 const char* route = env->GetStringUTFChars(jroute, NULL);
1030                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
1031                 env->ReleaseStringUTFChars(jroute, route);
1032                 return err;
1033         } else {
1034                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
1035         }
1036 }
1037 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1038         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
1039         if (route) {
1040                 return env->NewStringUTF(route);
1041         } else {
1042                 return NULL;
1043         }
1044 }
1045
1046 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
1047         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
1048 }
1049 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1050         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
1051 }
1052 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1053         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
1054 }
1055 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1056         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
1057 }
1058 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1059         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
1060 }
1061 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
1062         if (jnumber == 0) {
1063                 ms_error("cannot normalized null number");
1064         }
1065         const char* number = env->GetStringUTFChars(jnumber, NULL);
1066         int len = env->GetStringLength(jnumber);
1067         if (len == 0) {
1068                 ms_warning("cannot normalize empty number");
1069                 return jnumber;
1070         }
1071         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
1072         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
1073         jstring normalizedNumber = env->NewStringUTF(targetBuff);
1074         env->ReleaseStringUTFChars(jnumber, number);
1075         return normalizedNumber;
1076 }
1077 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
1078                                                                                                                                                         ,jobject thiz
1079                                                                                                                                                         ,jlong proxyCfg) {
1080         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
1081         if (domain) {
1082                 return env->NewStringUTF(domain);
1083         } else {
1084                 return NULL;
1085         }
1086 }
1087 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
1088         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
1089 }
1090
1091 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
1092                                                                                                                                         ,jobject thiz
1093                                                                                                                                         ,jlong proxyCfg
1094                                                                                                                                         ,jstring jprefix) {
1095         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
1096         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
1097         env->ReleaseStringUTFChars(jprefix, prefix);
1098 }
1099 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
1100                                                                                                                                                                 ,jobject thiz
1101                                                                                                                                                                 ,jlong proxyCfg
1102                                                                                                                                                                 ,jboolean val) {
1103         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
1104 }
1105 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1106         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
1107 }
1108
1109 //Auth Info
1110
1111 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
1112                 , jobject thiz
1113                 , jstring jusername
1114                 , jstring juserid
1115                 , jstring jpassword
1116                 , jstring jha1
1117                 , jstring jrealm) {
1118
1119         const char* username = env->GetStringUTFChars(jusername, NULL);
1120         const char* password = env->GetStringUTFChars(jpassword, NULL);
1121         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
1122
1123         env->ReleaseStringUTFChars(jusername, username);
1124         env->ReleaseStringUTFChars(jpassword, password);
1125         return auth;
1126
1127 }
1128 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
1129                 , jobject thiz
1130                 , jlong ptr) {
1131         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
1132 }
1133
1134 //LinphoneAddress
1135
1136 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
1137                                                                                                                                                                         ,jobject  thiz
1138                                                                                                                                                                         ,jstring juri
1139                                                                                                                                                                         ,jstring jdisplayName) {
1140         const char* uri = env->GetStringUTFChars(juri, NULL);
1141         LinphoneAddress* address = linphone_address_new(uri);
1142         if (jdisplayName && address) {
1143                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
1144                 linphone_address_set_display_name(address,displayName);
1145                 env->ReleaseStringUTFChars(jdisplayName, displayName);
1146         }
1147         env->ReleaseStringUTFChars(juri, uri);
1148
1149         return  (jlong) address;
1150 }
1151 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
1152                                                                                                                                                 ,jobject  thiz
1153                                                                                                                                                 ,jlong ptr) {
1154         linphone_address_destroy((LinphoneAddress*)ptr);
1155 }
1156
1157 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
1158                                                                                                                                                 ,jobject  thiz
1159                                                                                                                                                 ,jlong ptr) {
1160         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
1161         if (displayName) {
1162                 return env->NewStringUTF(displayName);
1163         } else {
1164                 return 0;
1165         }
1166 }
1167 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
1168                                                                                                                                                 ,jobject  thiz
1169                                                                                                                                                 ,jlong ptr) {
1170         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
1171         if (userName) {
1172                 return env->NewStringUTF(userName);
1173         } else {
1174                 return 0;
1175         }
1176 }
1177 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
1178                                                                                                                                                 ,jobject  thiz
1179                                                                                                                                                 ,jlong ptr) {
1180         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
1181         if (domain) {
1182                 return env->NewStringUTF(domain);
1183         } else {
1184                 return 0;
1185         }
1186 }
1187
1188 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
1189                                                                                                                                                 ,jobject  thiz
1190                                                                                                                                                 ,jlong ptr) {
1191         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
1192         jstring juri =env->NewStringUTF(uri);
1193         ms_free(uri);
1194         return juri;
1195 }
1196 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
1197                                                                                                                                                 ,jobject  thiz
1198                                                                                                                                                 ,jlong ptr) {
1199         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
1200         jstring juri =env->NewStringUTF(uri);
1201         ms_free(uri);
1202         return juri;
1203 }
1204 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
1205                                                                                                                                                 ,jobject  thiz
1206                                                                                                                                                 ,jlong address
1207                                                                                                                                                 ,jstring jdisplayName) {
1208         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
1209         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
1210         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
1211 }
1212
1213
1214 //CallLog
1215 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
1216                                                                                                                                                 ,jobject  thiz
1217                                                                                                                                                 ,jlong ptr) {
1218         return (jlong)((LinphoneCallLog*)ptr)->from;
1219 }
1220 extern "C" int Java_org_linphone_core_LinphoneCallLogImpl_getStatus(JNIEnv*  env
1221                                                                                                                                                 ,jobject  thiz
1222                                                                                                                                                 ,jlong ptr) {
1223         return (jlong)((LinphoneCallLog*)ptr)->status;
1224 }
1225 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
1226                                                                                                                                                 ,jobject  thiz
1227                                                                                                                                                 ,jlong ptr) {
1228         return (jlong)((LinphoneCallLog*)ptr)->to;
1229 }
1230 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
1231                                                                                                                                                 ,jobject  thiz
1232                                                                                                                                                 ,jlong ptr) {
1233         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1234 }
1235 extern "C" jstring Java_org_linphone_core_LinphoneCallLogImpl_getStartDate(JNIEnv*  env
1236                                                                                                                                                 ,jobject  thiz
1237                                                                                                                                                 ,jlong ptr) {
1238         jstring jvalue =env->NewStringUTF(((LinphoneCallLog*)ptr)->start_date);
1239         return jvalue;
1240 }
1241 extern "C" jint Java_org_linphone_core_LinphoneCallLogImpl_getCallDuration(JNIEnv*  env
1242                                                                                                                                                 ,jobject  thiz
1243                                                                                                                                                 ,jlong ptr) {
1244         return ((LinphoneCallLog*)ptr)->duration;
1245 }
1246
1247 /* CallStats */
1248 extern "C" int Java_org_linphone_core_LinphoneCallStatsImpl_getMediaType(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1249         return (int)((LinphoneCallStats *)stats_ptr)->type;
1250 }
1251 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderLossRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1252         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1253         const report_block_t *srb = NULL;
1254
1255         if (!stats->sent_rtcp)
1256                 return (jfloat)0.0;
1257         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1258         if (stats->sent_rtcp->b_cont != NULL)
1259                 msgpullup(stats->sent_rtcp, -1);
1260         if (rtcp_is_SR(stats->sent_rtcp))
1261                 srb = rtcp_SR_get_report_block(stats->sent_rtcp, 0);
1262         else if (rtcp_is_RR(stats->sent_rtcp))
1263                 srb = rtcp_RR_get_report_block(stats->sent_rtcp, 0);
1264         if (!srb)
1265                 return (jfloat)0.0;
1266         return (jfloat)(100.0 * report_block_get_fraction_lost(srb) / 256.0);
1267 }
1268 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverLossRate(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1269         const LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1270         const report_block_t *rrb = NULL;
1271
1272         if (!stats->received_rtcp)
1273                 return (jfloat)0.0;
1274         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1275         if (stats->received_rtcp->b_cont != NULL)
1276                 msgpullup(stats->received_rtcp, -1);
1277         if (rtcp_is_RR(stats->received_rtcp))
1278                 rrb = rtcp_RR_get_report_block(stats->received_rtcp, 0);
1279         else if (rtcp_is_SR(stats->received_rtcp))
1280                 rrb = rtcp_SR_get_report_block(stats->received_rtcp, 0);
1281         if (!rrb)
1282                 return (jfloat)0.0;
1283         return (jfloat)(100.0 * report_block_get_fraction_lost(rrb) / 256.0);
1284 }
1285 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1286         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1287         const LinphoneCall *call = (LinphoneCall *)call_ptr;
1288         const LinphoneCallParams *params = linphone_call_get_current_params(call);
1289         const PayloadType *pt;
1290         const report_block_t *srb = NULL;
1291
1292         if (!stats->sent_rtcp)
1293                 return (jfloat)0.0;
1294         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1295         if (stats->sent_rtcp->b_cont != NULL)
1296                 msgpullup(stats->sent_rtcp, -1);
1297         if (rtcp_is_SR(stats->sent_rtcp))
1298                 srb = rtcp_SR_get_report_block(stats->sent_rtcp, 0);
1299         else if (rtcp_is_RR(stats->sent_rtcp))
1300                 srb = rtcp_RR_get_report_block(stats->sent_rtcp, 0);
1301         if (!srb)
1302                 return (jfloat)0.0;
1303         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1304                 pt = linphone_call_params_get_used_audio_codec(params);
1305         else
1306                 pt = linphone_call_params_get_used_video_codec(params);
1307         return (jfloat)((float)report_block_get_interarrival_jitter(srb) / (float)pt->clock_rate);
1308 }
1309 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1310         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1311         const LinphoneCall *call = (LinphoneCall *)call_ptr;
1312         const LinphoneCallParams *params = linphone_call_get_current_params(call);
1313         const PayloadType *pt;
1314         const report_block_t *rrb = NULL;
1315
1316         if (!stats->received_rtcp)
1317                 return (jfloat)0.0;
1318         /* Perform msgpullup() to prevent crashes in rtcp_is_SR() or rtcp_is_RR() if the RTCP packet is composed of several mblk_t structure */
1319         if (stats->received_rtcp->b_cont != NULL)
1320                 msgpullup(stats->received_rtcp, -1);
1321         if (rtcp_is_SR(stats->received_rtcp))
1322                 rrb = rtcp_SR_get_report_block(stats->received_rtcp, 0);
1323         else if (rtcp_is_RR(stats->received_rtcp))
1324                 rrb = rtcp_RR_get_report_block(stats->received_rtcp, 0);
1325         if (!rrb)
1326                 return (jfloat)0.0;
1327         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1328                 pt = linphone_call_params_get_used_audio_codec(params);
1329         else
1330                 pt = linphone_call_params_get_used_video_codec(params);
1331         return (jfloat)((float)report_block_get_interarrival_jitter(rrb) / (float)pt->clock_rate);
1332 }
1333 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getRoundTripDelay(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1334         return (jfloat)((LinphoneCallStats *)stats_ptr)->round_trip_delay;
1335 }
1336 extern "C" jlong Java_org_linphone_core_LinphoneCallStatsImpl_getLatePacketsCumulativeNumber(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
1337         LinphoneCallStats *stats = (LinphoneCallStats *)stats_ptr;
1338         LinphoneCall *call = (LinphoneCall *)call_ptr;
1339         rtp_stats_t rtp_stats;
1340
1341         memset(&rtp_stats, 0, sizeof(rtp_stats));
1342         if (stats->type == LINPHONE_CALL_STATS_AUDIO)
1343                 audio_stream_get_local_rtp_stats(call->audiostream, &rtp_stats);
1344 #ifdef VIDEO_ENABLED
1345         else
1346                 video_stream_get_local_rtp_stats(call->videostream, &rtp_stats);
1347 #endif
1348         return (jlong)rtp_stats.outoftime;
1349 }
1350 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getJitterBufferSize(JNIEnv *env, jobject thiz, jlong stats_ptr) {
1351         return (jfloat)((LinphoneCallStats *)stats_ptr)->jitter_stats.jitter_buffer_size_ms;
1352 }
1353
1354 /*payloadType*/
1355 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
1356         PayloadType* pt = (PayloadType*)ptr;
1357         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
1358                                                                         ,payload_type_get_mime(pt)
1359                                                                         ,payload_type_get_rate(pt)
1360                                                                         ,payload_type_get_bitrate(pt));
1361         jstring jvalue =env->NewStringUTF(value);
1362         ms_free(value);
1363         return jvalue;
1364 }
1365 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
1366         PayloadType* pt = (PayloadType*)ptr;
1367         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
1368         return jvalue;
1369 }
1370 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
1371         PayloadType* pt = (PayloadType*)ptr;
1372         return payload_type_get_rate(pt);
1373 }
1374
1375 //LinphoneCall
1376 extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv*  env
1377                                                                                                                                                 ,jobject  thiz
1378                                                                                                                                                 ,jlong ptr) {
1379         LinphoneCall *call=(LinphoneCall*)ptr;
1380         linphone_call_unref(call);
1381 }
1382
1383 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1384                                                                                                                                                 ,jobject  thiz
1385                                                                                                                                                 ,jlong ptr) {
1386         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1387 }
1388
1389 extern "C" void Java_org_linphone_core_LinphoneCallImpl_takeSnapshot(   JNIEnv*  env
1390                                                                                                                                                 ,jobject  thiz
1391                                                                                                                                                 ,jlong ptr, jstring path) {
1392         const char* filePath = path != NULL ? env->GetStringUTFChars(path, NULL) : NULL;
1393         linphone_call_take_video_snapshot((LinphoneCall*)ptr, filePath);
1394 }
1395
1396 extern "C" void Java_org_linphone_core_LinphoneCallImpl_zoomVideo(              JNIEnv*  env
1397                                                                                                                                                 ,jobject  thiz
1398                                                                                                                                                 ,jlong ptr, jfloat zoomFactor, jfloat cx, jfloat cy) {
1399         linphone_call_zoom_video((LinphoneCall*)ptr, zoomFactor, &cx, &cy);
1400 }
1401
1402 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1403                                                                                                                                                 ,jobject  thiz
1404                                                                                                                                                 ,jlong ptr) {
1405         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1406 }
1407
1408 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1409                                                                                                                                                 ,jobject  thiz
1410                                                                                                                                                 ,jlong ptr) {
1411         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1412 }
1413
1414 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1415                                                                                                                                                 ,jobject  thiz
1416                                                                                                                                                 ,jlong ptr) {
1417         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1418 }
1419 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1420                                                                                                                                                 ,jobject  thiz
1421                                                                                                                                                 ,jlong ptr
1422                                                                                                                                                 ,jboolean value) {
1423         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1424 }
1425 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1426                                                                                                                                                 ,jobject  thiz
1427                                                                                                                                                 ,jlong ptr) {
1428         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1429 }
1430
1431 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1432                                                                                                                                                 ,jobject  thiz
1433                                                                                                                                                 ,jlong ptr
1434                                                                                                                                                 ,jboolean value) {
1435         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1436 }
1437 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1438                                                                                                                                                 ,jobject  thiz
1439                                                                                                                                                 ,jlong ptr) {
1440         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1441 }
1442
1443 extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(     JNIEnv*  env
1444                                                                                                                                                 ,jobject  thiz
1445                                                                                                                                                 ,jlong ptr) {
1446         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(linphone_call_get_core((LinphoneCall*)ptr));       
1447         return lcd->getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr));
1448 }
1449
1450 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1451                                                                                                                                                 ,jobject  thiz
1452                                                                                                                                                 ,jlong ptr) {
1453         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1454 }
1455
1456 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1457                                                                                                                                                 ,jobject  thiz
1458                                                                                                                                                 ,jlong ptr) {
1459         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1460 }
1461
1462
1463 //LinphoneFriend
1464 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1465                                                                                                                                                 ,jobject  thiz
1466                                                                                                                                                 ,jstring jFriendUri) {
1467         LinphoneFriend* lResult;
1468
1469         if (jFriendUri) {
1470                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1471                 lResult= linphone_friend_new_with_addr(friendUri);
1472                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1473         } else {
1474                 lResult = linphone_friend_new();
1475         }
1476         return (long)lResult;
1477 }
1478 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1479                                                                                                                                                 ,jobject  thiz
1480                                                                                                                                                 ,jlong ptr
1481                                                                                                                                                 ,jlong linphoneAddress) {
1482         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1483 }
1484 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1485                                                                                                                                                 ,jobject  thiz
1486                                                                                                                                                 ,jlong ptr) {
1487         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1488 }
1489 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1490                                                                                                                                                 ,jobject  thiz
1491                                                                                                                                                 ,jlong ptr
1492                                                                                                                                                 ,jint policy) {
1493         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1494 }
1495 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1496                                                                                                                                                 ,jobject  thiz
1497                                                                                                                                                 ,jlong ptr) {
1498         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1499 }
1500 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1501                                                                                                                                                 ,jobject  thiz
1502                                                                                                                                                 ,jlong ptr
1503                                                                                                                                                 ,jboolean value) {
1504         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1505 }
1506 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1507                                                                                                                                                 ,jobject  thiz
1508                                                                                                                                                 ,jlong ptr) {
1509         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1510 }
1511 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1512                                                                                                                                                 ,jobject  thiz
1513                                                                                                                                                 ,jlong ptr) {
1514         return linphone_friend_get_status((LinphoneFriend*)ptr);
1515 }
1516 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1517                                                                                                                                                 ,jobject  thiz
1518                                                                                                                                                 ,jlong ptr) {
1519         return linphone_friend_edit((LinphoneFriend*)ptr);
1520 }
1521 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1522                                                                                                                                                 ,jobject  thiz
1523                                                                                                                                                 ,jlong ptr) {
1524          linphone_friend_done((LinphoneFriend*)ptr);
1525 }
1526 //LinphoneChatRoom
1527 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1528                                                                                                                                                 ,jobject  thiz
1529                                                                                                                                                 ,jlong ptr) {
1530         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1531 }
1532 extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage(JNIEnv*  env
1533                                                                                                                                                 ,jobject  thiz
1534                                                                                                                                                 ,jlong ptr
1535                                                                                                                                                 ,jstring jmessage) {
1536         const char* message = env->GetStringUTFChars(jmessage, NULL);
1537         LinphoneChatMessage *chatMessage = linphone_chat_room_create_message((LinphoneChatRoom *)ptr, message);
1538         env->ReleaseStringUTFChars(jmessage, message);
1539
1540         return (jlong) chatMessage;
1541 }
1542 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setUserData(JNIEnv*  env
1543                                                                                                                                                 ,jobject  thiz
1544                                                                                                                                                 ,jlong ptr) {
1545         jobject ud = env->NewGlobalRef(thiz);
1546         linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr,(void*) ud);
1547 }
1548 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getMessage(JNIEnv*  env
1549                                                                                                                                                 ,jobject  thiz
1550                                                                                                                                                 ,jlong ptr) {
1551         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_message((LinphoneChatMessage*)ptr));
1552         return jvalue;
1553 }
1554 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getExternalBodyUrl(JNIEnv*  env
1555                                                                                                                                                 ,jobject  thiz
1556                                                                                                                                                 ,jlong ptr) {
1557         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_external_body_url((LinphoneChatMessage*)ptr));
1558         return jvalue;
1559 }
1560 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setExternalBodyUrl(JNIEnv*  env
1561                                                                                                                                                 ,jobject  thiz
1562                                                                                                                                                 ,jlong ptr
1563                                                                                                                                                 ,jstring jurl) {
1564         const char* url = env->GetStringUTFChars(jurl, NULL);
1565         linphone_chat_message_set_external_body_url((LinphoneChatMessage *)ptr, url);
1566         env->ReleaseStringUTFChars(jurl, url);
1567 }
1568 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getFrom(JNIEnv*  env
1569                                                                                                                                                 ,jobject  thiz
1570                                                                                                                                                 ,jlong ptr) {
1571         return (jlong) linphone_chat_message_get_from((LinphoneChatMessage*)ptr);
1572 }
1573 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getPeerAddress(JNIEnv*  env
1574                                                                                                                                                 ,jobject  thiz
1575                                                                                                                                                 ,jlong ptr) {
1576         return (jlong) linphone_chat_message_get_peer_address((LinphoneChatMessage*)ptr);
1577 }
1578 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1579                                                                                                                                                 ,jobject  thiz
1580                                                                                                                                                 ,jlong ptr
1581                                                                                                                                                 ,jstring jmessage) {
1582         const char* message = env->GetStringUTFChars(jmessage, NULL);
1583         linphone_chat_room_send_message((LinphoneChatRoom*)ptr, message);
1584         env->ReleaseStringUTFChars(jmessage, message);
1585 }
1586
1587 static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessageState state, void* ud) {
1588         JNIEnv *env = 0;
1589         jint result = jvm->AttachCurrentThread(&env,NULL);
1590         if (result != 0) {
1591                 ms_error("cannot attach VM\n");
1592                 return;
1593         }
1594
1595         jobject listener = (jobject) ud;
1596         jclass clazz = (jclass) env->GetObjectClass(listener);
1597         jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
1598
1599         LinphoneCore *lc = linphone_chat_room_get_lc(linphone_chat_message_get_chat_room(msg));
1600         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
1601         env->CallVoidMethod(
1602                         listener,
1603                         method,
1604                         (jobject)linphone_chat_message_get_user_data(msg),
1605                         env->CallStaticObjectMethod(lcData->chatMessageStateClass,lcData->chatMessageStateFromIntId,(jint)state));
1606
1607         if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) {
1608                 env->DeleteGlobalRef(listener);
1609         }
1610 }
1611 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv*  env
1612                                                                                                                                                 ,jobject  thiz
1613                                                                                                                                                 ,jlong ptr
1614                                                                                                                                                 ,jlong jmessage
1615                                                                                                                                                 ,jobject jlistener) {
1616         jobject listener = env->NewGlobalRef(jlistener);
1617         linphone_chat_room_send_message2((LinphoneChatRoom*)ptr, (LinphoneChatMessage*)jmessage, chat_room_impl_callback, (void*)listener);
1618 }
1619 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1620                                                                                                                                                 ,jobject thiz
1621                                                                                                                                                 ,jlong lc
1622                                                                                                                                                 ,jobject obj) {
1623         jobject oldWindow = (jobject) linphone_core_get_native_video_window_id((LinphoneCore*)lc);
1624         if (oldWindow != NULL) {
1625                 env->DeleteGlobalRef(oldWindow);
1626         }
1627         if (obj != NULL) {
1628                 obj = env->NewGlobalRef(obj);
1629         }
1630         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1631 }
1632
1633 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreviewWindowId(JNIEnv* env
1634                                                                                                                                                 ,jobject thiz
1635                                                                                                                                                 ,jlong lc
1636                                                                                                                                                 ,jobject obj) {
1637         jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id((LinphoneCore*)lc);
1638         if (oldWindow != NULL) {
1639                 env->DeleteGlobalRef(oldWindow);
1640         }
1641         if (obj != NULL) {
1642                 obj = env->NewGlobalRef(obj);
1643         }
1644         linphone_core_set_native_preview_window_id((LinphoneCore*)lc,(unsigned long)obj);
1645 }
1646
1647 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDeviceRotation(JNIEnv* env
1648                                                                                                                                                 ,jobject thiz
1649                                                                                                                                                 ,jlong lc
1650                                                                                                                                                 ,jint rotation) {
1651         linphone_core_set_device_rotation((LinphoneCore*)lc,rotation);
1652 }
1653
1654
1655 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1656         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1657 }
1658
1659 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1660         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1661 }
1662
1663 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1664         const char* server = NULL;
1665         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1666         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1667         if (server) env->ReleaseStringUTFChars(jserver,server);
1668 }
1669
1670 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1671         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1672         if (ret==NULL) return NULL;
1673         jstring jvalue =env->NewStringUTF(ret);
1674         return jvalue;
1675 }
1676
1677 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1678         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1679 }
1680
1681 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1682         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1683 }
1684
1685 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1686         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1687 }
1688
1689 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_localConferenceMode(JNIEnv *env, jobject thiz, jlong lcp){
1690         return linphone_call_params_local_conference_mode((LinphoneCallParams*)lcp);
1691 }
1692
1693 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1694         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1695 }
1696 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1697         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1698 }
1699
1700 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteParams(JNIEnv *env, jobject thiz, jlong lc){
1701         if (linphone_call_get_remote_params((LinphoneCall*)lc) == NULL) {
1702                         return (jlong) 0;
1703         }
1704         return (jlong) linphone_call_params_copy(linphone_call_get_remote_params((LinphoneCall*)lc));
1705 }
1706
1707 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1708         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1709 }
1710
1711 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1712         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1713 }
1714
1715 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_cameraEnabled(JNIEnv *env, jobject thiz, jlong lc){
1716         linphone_call_camera_enabled((LinphoneCall *)lc);
1717 }
1718
1719 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1720         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
1721         return  lcd->getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params));
1722 }
1723
1724 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1725         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1726 }
1727
1728 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1729         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1730 }
1731
1732
1733 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1734         MSVideoSize vsize;
1735         vsize.width = (int)width;
1736         vsize.height = (int)height;
1737         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1738 }
1739
1740 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1741         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1742     jintArray arr = env->NewIntArray(2);
1743         int tVsize [2]= {vsize.width,vsize.height};
1744     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1745     return arr;
1746 }
1747
1748 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1749         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1750 }
1751
1752 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1753         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1754 }
1755
1756 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1757         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
1758 }
1759
1760 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1761         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
1762 }
1763
1764 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1765         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1766 }
1767 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1768         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1769 }
1770
1771 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1772         linphone_call_get_duration((LinphoneCall *) ptr);
1773 }
1774
1775 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1776         LCSipTransports tr;
1777         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1778                 switch (code) {
1779         case 0:
1780                 return tr.udp_port;
1781         case 1:
1782                 return tr.tcp_port;
1783         case 3:
1784                 return tr.tls_port;
1785         default:
1786                 return -2;
1787         }
1788 }
1789
1790 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1791         LinphoneCore *lc = (LinphoneCore *) ptr;
1792         LCSipTransports tr;
1793         tr.udp_port = udp;
1794         tr.tcp_port = tcp;
1795         tr.tls_port = tls;
1796
1797         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1798 }
1799
1800 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1801               ,jlong lc, jboolean enable) {
1802               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1803 }
1804
1805 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
1806               ,jlong ptr, jint db) {
1807         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
1808 }
1809
1810 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1811         return linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1812 }
1813 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1814         return linphone_core_pause_all_calls((LinphoneCore *) pCore);
1815 }
1816 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1817         return linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1818 }
1819 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInConference(JNIEnv *env,jobject thiz,jlong pCore) {
1820         return linphone_core_is_in_conference((LinphoneCore *) pCore);
1821 }
1822 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_enterConference(JNIEnv *env,jobject thiz,jlong pCore) {
1823         return 0 == linphone_core_enter_conference((LinphoneCore *) pCore);
1824 }
1825 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_leaveConference(JNIEnv *env,jobject thiz,jlong pCore) {
1826         linphone_core_leave_conference((LinphoneCore *) pCore);
1827 }
1828 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAllToConference(JNIEnv *env,jobject thiz,jlong pCore) {
1829         linphone_core_add_all_to_conference((LinphoneCore *) pCore);
1830 }
1831 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addToConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1832         linphone_core_add_to_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1833 }
1834 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFromConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1835         linphone_core_remove_from_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1836 }
1837
1838 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateConference(JNIEnv *env,jobject thiz,jlong pCore) {
1839         linphone_core_terminate_conference((LinphoneCore *) pCore);
1840 }
1841 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv *env,jobject thiz,jlong pCore) {
1842         return linphone_core_get_conference_size((LinphoneCore *) pCore);
1843 }
1844 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1845         linphone_core_terminate_all_calls((LinphoneCore *) pCore);
1846 }
1847 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) {
1848         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1849         LinphoneCall* lCall = (LinphoneCall*) ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position);
1850         return lcd->getCall(env,lCall);
1851 }
1852 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) {
1853         return ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore));
1854 }
1855
1856 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jstring jReferTo) {
1857         const char* cReferTo=env->GetStringUTFChars(jReferTo, NULL);
1858         linphone_core_transfer_call((LinphoneCore *) pCore, (LinphoneCall *) pCall, cReferTo);
1859         env->ReleaseStringUTFChars(jReferTo, cReferTo);
1860 }
1861 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jlong pDestCall) {
1862         linphone_core_transfer_call_to_another((LinphoneCore *) pCore, (LinphoneCall *) pCall, (LinphoneCall *) pDestCall);
1863 }
1864
1865 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
1866         if (jFile) {
1867                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
1868                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
1869                 env->ReleaseStringUTFChars(jFile, cFile);
1870         } else {
1871                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
1872         }
1873 }
1874
1875 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_findCallFromUri(JNIEnv *env,jobject thiz,jlong pCore, jstring jUri) {
1876         const char* cUri=env->GetStringUTFChars(jUri, NULL);
1877         LinphoneCall *call= (LinphoneCall *) linphone_core_find_call_from_uri((LinphoneCore *) pCore,cUri);
1878         env->ReleaseStringUTFChars(jUri, cUri);
1879         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1880         return (jobject) lcdata->getCall(env,call);
1881 }
1882
1883
1884 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_setVideoDevice(JNIEnv *env,jobject thiz,jlong pCore,jint id) {
1885         LinphoneCore* lc = (LinphoneCore *) pCore;
1886         const char** devices = linphone_core_get_video_devices(lc);
1887         if (devices == NULL) {
1888                 ms_error("No existing video devices\n");
1889                 return -1;
1890         }
1891         int i;
1892         for(i=0; i<=id; i++) {
1893                 if (devices[i] == NULL)
1894                         break;
1895                 ms_message("Existing device %d : %s\n", i, devices[i]);
1896                 if (i==id) {
1897                         return linphone_core_set_video_device(lc, devices[i]);
1898                 }
1899         }
1900         return -1;
1901 }
1902
1903 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDevice(JNIEnv *env,jobject thiz,jlong pCore) {
1904         LinphoneCore* lc = (LinphoneCore *) pCore;
1905         const char** devices = linphone_core_get_video_devices(lc);
1906         if (devices == NULL) {
1907                 ms_error("No existing video devices\n");
1908                 return -1;
1909         }
1910         const char* cam = linphone_core_get_video_device(lc);
1911         if (cam == NULL) {
1912                 ms_error("No current video device\n");
1913         } else {
1914                 int i=0;
1915                 while(devices[i] != NULL) {
1916                         if (strcmp(devices[i], cam) == 0)
1917                                 return i;
1918                         i++;
1919                 }
1920         }
1921         ms_warning("Returning default (0) device\n");
1922         return 0;
1923 }
1924
1925 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
1926         LinphoneCall *call = (LinphoneCall *) ptr;
1927         const char* token = linphone_call_get_authentication_token(call);
1928         if (token == NULL) return NULL;
1929         return env->NewStringUTF(token);
1930 }
1931 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
1932         LinphoneCall *call = (LinphoneCall *) ptr;
1933         return linphone_call_get_authentication_token_verified(call);
1934 }
1935 extern "C" void Java_org_linphone_core_LinphoneCallImpl_setAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr,jboolean verified) {
1936         LinphoneCall *call = (LinphoneCall *) ptr;
1937         linphone_call_set_authentication_token_verified(call, verified);
1938 }
1939
1940 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getPlayVolume(JNIEnv* env, jobject thiz, jlong ptr) {
1941         LinphoneCall *call = (LinphoneCall *) ptr;
1942         return linphone_call_get_play_volume(call);
1943 }
1944
1945 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_soundResourcesLocked(JNIEnv* env,jobject thiz,jlong ptr){
1946         return linphone_core_sound_resources_locked((LinphoneCore *) ptr);
1947 }
1948
1949 // Needed by Galaxy S (can't switch to/from speaker while playing and still keep mic working)
1950 // Implemented directly in msandroid.cpp (sound filters for Android).
1951 extern "C" void msandroid_hack_speaker_state(bool speakerOn);
1952
1953 extern "C" void Java_org_linphone_LinphoneManager_hackSpeakerState(JNIEnv*  env,jobject thiz,jboolean speakerOn){
1954         msandroid_hack_speaker_state(speakerOn);
1955 }
1956 // End Galaxy S hack functions
1957
1958
1959 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMaxCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1960         return (jint) linphone_core_get_max_calls((LinphoneCore *) pCore);
1961 }
1962 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMaxCalls(JNIEnv *env,jobject thiz,jlong pCore, jint max) {
1963         linphone_core_set_max_calls((LinphoneCore *) pCore, (int) max);
1964 }
1965
1966 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror(JNIEnv *env,jobject thiz,jlong pCore,
1967                 jstring jHost, jint port, jint mirror, jint delay) {
1968         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
1969         if (!tunnel) return;
1970         const char* cHost=env->GetStringUTFChars(jHost, NULL);
1971         linphone_tunnel_add_server_and_mirror(tunnel, cHost, port, mirror, delay);
1972         env->ReleaseStringUTFChars(jHost, cHost);
1973 }
1974
1975 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelSetHttpProxy(JNIEnv *env,jobject thiz,jlong pCore,
1976                 jstring jHost, jint port, jstring username, jstring password) {
1977
1978         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
1979         if (!tunnel) return;
1980         const char* cHost=(jHost!=NULL) ? env->GetStringUTFChars(jHost, NULL) : NULL;
1981         const char* cUsername= (username!=NULL) ? env->GetStringUTFChars(username, NULL) : NULL;
1982         const char* cPassword= (password!=NULL) ? env->GetStringUTFChars(password, NULL) : NULL;
1983         linphone_tunnel_set_http_proxy(tunnel,cHost, port,cUsername,cPassword);
1984         if (cHost) env->ReleaseStringUTFChars(jHost, cHost);
1985         if (cUsername) env->ReleaseStringUTFChars(username, cUsername);
1986         if (cPassword) env->ReleaseStringUTFChars(password, cPassword);
1987 }
1988
1989
1990 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAutoDetect(JNIEnv *env,jobject thiz,jlong pCore) {
1991         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1992         linphone_tunnel_auto_detect(tunnel);
1993
1994 }
1995
1996 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelCleanServers(JNIEnv *env,jobject thiz,jlong pCore) {
1997         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1998         linphone_tunnel_clean_servers(tunnel);
1999 }
2000
2001 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnable(JNIEnv *env,jobject thiz,jlong pCore, jboolean enable) {
2002         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
2003         linphone_tunnel_enable(tunnel, enable);
2004 }
2005
2006
2007 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUserAgent(JNIEnv *env,jobject thiz,jlong pCore, jstring name, jstring version){
2008         const char* cname=env->GetStringUTFChars(name, NULL);
2009         const char* cversion=env->GetStringUTFChars(version, NULL);
2010         linphone_core_set_user_agent(cname,cversion);
2011         env->ReleaseStringUTFChars(name, cname);
2012         env->ReleaseStringUTFChars(version, cversion);
2013 }
2014
2015 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isTunnelAvailable(JNIEnv *env,jobject thiz){
2016         return linphone_core_tunnel_available();
2017 }
2018
2019 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPolicy(JNIEnv *env, jobject thiz, jlong lc, jboolean autoInitiate, jboolean autoAccept){
2020         LinphoneVideoPolicy vpol;
2021         vpol.automatically_initiate = autoInitiate;
2022         vpol.automatically_accept = autoAccept;
2023         linphone_core_set_video_policy((LinphoneCore *)lc, &vpol);
2024 }
2025
2026 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCpuCountNative(JNIEnv *env, jobject thiz, jint count) {
2027         ms_set_cpu_count(count);
2028 }
2029
2030 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getVersion(JNIEnv*  env,jobject  thiz,jlong ptr) {
2031         jstring jvalue =env->NewStringUTF(linphone_core_get_version());
2032         return jvalue;
2033 }