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