]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
add ec calibrator to Android
[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
22 #include "mediastreamer2/msjava.h"
23
24 #ifdef ANDROID
25 #include <android/log.h>
26 extern "C" void libmsilbc_init();
27 extern "C" void libmsx264_init();
28 #endif /*ANDROID*/
29
30 static JavaVM *jvm=0;
31
32 #ifdef ANDROID
33 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
34         int prio;
35         switch(lev){
36         case ORTP_DEBUG:        prio = ANDROID_LOG_DEBUG;       break;
37         case ORTP_MESSAGE:      prio = ANDROID_LOG_INFO;        break;
38         case ORTP_WARNING:      prio = ANDROID_LOG_WARN;        break;
39         case ORTP_ERROR:        prio = ANDROID_LOG_ERROR;       break;
40         case ORTP_FATAL:        prio = ANDROID_LOG_FATAL;       break;
41         default:                prio = ANDROID_LOG_DEFAULT;     break;
42         }
43         __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
44 }
45 #endif /*ANDROID*/
46
47 JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
48 {
49 #ifdef ANDROID
50         ms_set_jvm(ajvm);
51 #endif /*ANDROID*/
52         jvm=ajvm;
53         return JNI_VERSION_1_2;
54 }
55
56
57 //LinphoneFactory
58 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
59                 ,jobject  thiz
60                 ,jboolean isDebug) {
61         if (isDebug) {
62                 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
63         } else {
64                 linphone_core_disable_logs();
65         }
66 }
67 // LinphoneCore
68
69 class LinphoneCoreData {
70 public:
71         LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {
72
73                 core = env->NewGlobalRef(lc);
74                 listener = env->NewGlobalRef(alistener);
75                 userdata = auserdata?env->NewGlobalRef(auserdata):0;
76                 memset(&vTable,0,sizeof(vTable));
77                 vTable.show = showInterfaceCb;
78                 vTable.auth_info_requested = authInfoRequested;
79                 vTable.display_status = displayStatusCb;
80                 vTable.display_message = displayMessageCb;
81                 vTable.display_warning = displayMessageCb;
82                 vTable.global_state_changed = globalStateChange;
83                 vTable.registration_state_changed = registrationStateChange;
84                 vTable.call_state_changed = callStateChange;
85                 vTable.text_received = text_received;
86                 vTable.new_subscription_request = new_subscription_request;
87                 vTable.notify_presence_recv = notify_presence_recv;
88
89                 listernerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
90                 /*displayStatus(LinphoneCore lc,String message);*/
91                 displayStatusId = env->GetMethodID(listernerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
92                 /*void generalState(LinphoneCore lc,int state); */
93                 globalStateId = env->GetMethodID(listernerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
94                 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
95                 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
96                 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
97                 registrationStateId = env->GetMethodID(listernerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
98                 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
99                 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
100                 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
101                 callStateId = env->GetMethodID(listernerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
102                 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
103                 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
104                 /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
105                 ecCalibrationStatusId = env->GetMethodID(listernerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
106                 ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
107                 ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
108                 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
109                 newSubscriptionRequestId = env->GetMethodID(listernerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
110
111                 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
112                 notifyPresenceReceivedId = env->GetMethodID(listernerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
113
114                 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
115                 textReceivedId = env->GetMethodID(listernerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
116
117                 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
118                 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
119
120                 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
121                 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
122
123                 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
124                 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
125
126                 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
127                 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
128
129                 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
130                 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
131
132         }
133
134         ~LinphoneCoreData() {
135                 JNIEnv *env = 0;
136                 jvm->AttachCurrentThread(&env,NULL);
137                 env->DeleteGlobalRef(core);
138                 env->DeleteGlobalRef(listener);
139                 if (userdata) env->DeleteGlobalRef(userdata);
140                 env->DeleteGlobalRef(listernerClass);
141                 env->DeleteGlobalRef(globalStateClass);
142                 env->DeleteGlobalRef(registrationStateClass);
143                 env->DeleteGlobalRef(callStateClass);
144                 env->DeleteGlobalRef(proxyClass);
145                 env->DeleteGlobalRef(callClass);
146                 env->DeleteGlobalRef(chatRoomClass);
147                 env->DeleteGlobalRef(friendClass);
148
149         }
150         jobject core;
151         jobject listener;
152         jobject userdata;
153
154         jclass listernerClass;
155         jmethodID displayStatusId;
156         jmethodID newSubscriptionRequestId;
157         jmethodID notifyPresenceReceivedId;
158         jmethodID textReceivedId;
159
160         jclass globalStateClass;
161         jmethodID globalStateId;
162         jmethodID globalStateFromIntId;
163
164         jclass registrationStateClass;
165         jmethodID registrationStateId;
166         jmethodID registrationStateFromIntId;
167
168         jclass callStateClass;
169         jmethodID callStateId;
170         jmethodID callStateFromIntId;
171
172         jclass ecCalibratorStatusClass;
173         jmethodID ecCalibrationStatusId;
174         jmethodID ecCalibratorStatusFromIntId;
175
176         jclass proxyClass;
177         jmethodID proxyCtrId;
178
179         jclass callClass;
180         jmethodID callCtrId;
181
182         jclass chatRoomClass;
183         jmethodID chatRoomCtrId;
184
185         jclass friendClass;
186         jmethodID friendCtrId;
187
188         jclass addressClass;
189         jmethodID addressCtrId;
190
191         LinphoneCoreVTable vTable;
192
193         static void showInterfaceCb(LinphoneCore *lc) {
194
195         }
196         static void byeReceivedCb(LinphoneCore *lc, const char *from) {
197
198         }
199         static void displayStatusCb(LinphoneCore *lc, const char *message) {
200                 JNIEnv *env = 0;
201                 jint result = jvm->AttachCurrentThread(&env,NULL);
202                 if (result != 0) {
203                         ms_error("cannot attach VM\n");
204                         return;
205                 }
206                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
207                 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
208         }
209         static void displayMessageCb(LinphoneCore *lc, const char *message) {
210
211         }
212         static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
213
214         }
215         static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
216                 JNIEnv *env = 0;
217                 jint result = jvm->AttachCurrentThread(&env,NULL);
218                 if (result != 0) {
219                         ms_error("cannot attach VM\n");
220                         return;
221                 }
222                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
223                 env->CallVoidMethod(lcData->listener
224                                                         ,lcData->globalStateId
225                                                         ,lcData->core
226                                                         ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
227                                                         message ? env->NewStringUTF(message) : NULL);
228         }
229         static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
230                 JNIEnv *env = 0;
231                 jint result = jvm->AttachCurrentThread(&env,NULL);
232                 if (result != 0) {
233                         ms_error("cannot attach VM\n");
234                         return;
235                 }
236                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
237                 env->CallVoidMethod(lcData->listener
238                                                         ,lcData->registrationStateId
239                                                         ,lcData->core
240                                                         ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
241                                                         ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
242                                                         message ? env->NewStringUTF(message) : NULL);
243         }
244         static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
245                 JNIEnv *env = 0;
246                 jint result = jvm->AttachCurrentThread(&env,NULL);
247                 if (result != 0) {
248                         ms_error("cannot attach VM\n");
249                         return;
250                 }
251                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
252                 env->CallVoidMethod(lcData->listener
253                                                         ,lcData->callStateId
254                                                         ,lcData->core
255                                                         ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
256                                                         ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
257                                                         message ? env->NewStringUTF(message) : NULL);
258         }
259         static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
260                 JNIEnv *env = 0;
261                 jint result = jvm->AttachCurrentThread(&env,NULL);
262                 if (result != 0) {
263                         ms_error("cannot attach VM\n");
264                         return;
265                 }
266                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
267                 env->CallVoidMethod(lcData->listener
268                                                         ,lcData->notifyPresenceReceivedId
269                                                         ,lcData->core
270                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
271         }
272         static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
273                 JNIEnv *env = 0;
274                 jint result = jvm->AttachCurrentThread(&env,NULL);
275                 if (result != 0) {
276                         ms_error("cannot attach VM\n");
277                         return;
278                 }
279                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
280                 env->CallVoidMethod(lcData->listener
281                                                         ,lcData->newSubscriptionRequestId
282                                                         ,lcData->core
283                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
284                                                         ,url ? env->NewStringUTF(url) : NULL);
285         }
286         static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
287                 JNIEnv *env = 0;
288                 jint result = jvm->AttachCurrentThread(&env,NULL);
289                 if (result != 0) {
290                         ms_error("cannot attach VM\n");
291                         return;
292                 }
293                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
294                 env->CallVoidMethod(lcData->listener
295                                                         ,lcData->textReceivedId
296                                                         ,lcData->core
297                                                         ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
298                                                         ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
299                                                         ,message ? env->NewStringUTF(message) : NULL);
300         }
301         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
302                 JNIEnv *env = 0;
303                 jint result = jvm->AttachCurrentThread(&env,NULL);
304                 if (result != 0) {
305                         ms_error("cannot attach VM\n");
306                         return;
307                 }
308                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
309                 env->CallVoidMethod(lcData->listener
310                                                         ,lcData->ecCalibrationStatusId
311                                                         ,lcData->core
312                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
313                                                         ,delay_ms
314                                                         ,data ? data : NULL);
315                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
316                         //final state, releasing global ref
317                         env->DeleteGlobalRef((jobject)data);
318                 }
319
320         }
321
322
323 };
324 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
325                 ,jobject  thiz
326                 ,jobject jlistener
327                 ,jstring juserConfig
328                 ,jstring jfactoryConfig
329                 ,jobject  juserdata){
330
331         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
332         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
333         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
334
335 #ifdef HAVE_ILBC
336         libmsilbc_init(); // requires an fpu
337 #endif
338 #ifdef VIDEO_ENABLED
339         libmsx264_init();
340 #endif
341         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
342                         ,userConfig
343                         ,factoryConfig
344                         ,ldata);
345         //clear auth info list
346         linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
347         //clear existing proxy config
348         linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
349
350         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
351         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
352         return nativePtr;
353 }
354 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
355                 ,jobject  thiz
356                 ,jlong lc) {
357         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
358         linphone_core_destroy((LinphoneCore*)lc);
359         delete lcData;
360 }
361
362 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
363         linphone_core_clear_proxy_config((LinphoneCore*)lc);
364 }
365
366 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
367                 ,jobject  thiz
368                 ,jlong lc
369                 ,jlong pc) {
370         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
371 }
372 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
373                 ,jobject  thiz
374                 ,jlong lc) {
375         LinphoneProxyConfig *config=0;
376         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
377         return (jlong)config;
378 }
379
380 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig(  JNIEnv*  env
381                 ,jobject  thiz
382                 ,jobject jproxyCfg
383                 ,jlong lc
384                 ,jlong pc) {
385         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
386         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
387
388         return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
389 }
390
391 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
392         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
393 }
394
395 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
396                 ,jobject  thiz
397                 ,jlong lc
398                 ,jlong pc) {
399         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
400 }
401 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
402                 ,jobject  thiz
403                 ,jlong lc) {
404         linphone_core_iterate((LinphoneCore*)lc);
405 }
406 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_invite(        JNIEnv*  env
407                 ,jobject  thiz
408                 ,jlong lc
409                 ,jstring juri) {
410         const char* uri = env->GetStringUTFChars(juri, NULL);
411         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
412         env->ReleaseStringUTFChars(juri, uri);
413         return (jlong)lCall;
414 }
415 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv*  env
416                 ,jobject  thiz
417                 ,jlong lc
418                 ,jlong to) {
419         return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
420 }
421
422 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
423                 ,jobject  thiz
424                 ,jlong lc
425                 ,jlong call) {
426         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
427 }
428
429 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
430                 ,jobject  thiz
431                 ,jlong lc) {
432         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
433 }
434 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
435                 ,jobject  thiz
436                 ,jlong lc) {
437
438         return linphone_core_in_call((LinphoneCore*)lc);
439 }
440 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
441                 ,jobject  thiz
442                 ,jlong lc) {
443
444         return linphone_core_inc_invite_pending((LinphoneCore*)lc);
445 }
446 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
447                 ,jobject  thiz
448                 ,jlong lc
449                 ,jlong call) {
450
451         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
452 }
453
454 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
455                 ,jobject  thiz
456                 ,jlong lc
457                 ,jint position) {
458                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
459 }
460 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
461                 ,jobject  thiz
462                 ,jlong lc) {
463                 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
464 }
465 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
466                 ,jobject  thiz
467                 ,jlong lc
468                 ,jboolean isReachable) {
469                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
470 }
471
472 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
473                 ,jobject  thiz
474                 ,jlong lc
475                 ,jfloat gain) {
476                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
477 }
478
479 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(       JNIEnv*  env
480                 ,jobject  thiz
481                 ,jlong lc) {
482                 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
483 }
484
485 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
486                 ,jobject  thiz
487                 ,jlong lc
488                 ,jboolean isMuted) {
489                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
490 }
491
492 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
493                 ,jobject  thiz
494                 ,jlong lc
495                 ,jstring jurl) {
496         const char* url = env->GetStringUTFChars(jurl, NULL);
497         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
498         env->ReleaseStringUTFChars(jurl, url);
499         return result;
500 }
501 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
502                 ,jobject  thiz
503                 ,jlong lc
504                 ,jchar dtmf) {
505         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
506 }
507 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
508                 ,jobject  thiz
509                 ,jlong lc
510                 ,jchar dtmf
511                 ,jint duration) {
512         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
513 }
514 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
515                 ,jobject  thiz
516                 ,jlong lc) {
517         linphone_core_stop_dtmf((LinphoneCore*)lc);
518 }
519
520 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
521                                                                                                                                                 ,jobject  thiz
522                                                                                                                                                 ,jlong lc) {
523         linphone_core_clear_call_logs((LinphoneCore*)lc);
524 }
525 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
526                 ,jobject  thiz
527                 ,jlong lc) {
528         return linphone_core_is_mic_muted((LinphoneCore*)lc);
529 }
530 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
531                                                                                                                                                         ,jobject  thiz
532                                                                                                                                                         ,jlong lc
533                                                                                                                                                         ,jstring jmime
534                                                                                                                                                         ,jint rate) {
535         const char* mime = env->GetStringUTFChars(jmime, NULL);
536         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
537         env->ReleaseStringUTFChars(jmime, mime);
538         return result;
539 }
540 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
541                                                                                                                                                         ,jobject  thiz
542                                                                                                                                                         ,jlong lc) {
543         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
544         int codecsCount = ms_list_size(codecs);
545         jlongArray jCodecs = env->NewLongArray(codecsCount);
546         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
547
548         for (int i = 0; i < codecsCount; i++ ) {
549                 jInternalArray[i] = (unsigned long) (codecs->data);
550                 codecs = codecs->next;
551         }
552
553         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
554
555         return jCodecs;
556 }
557
558 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
559                                                                                                                                                         ,jobject  thiz
560                                                                                                                                                         ,jlong lc
561                                                                                                                                                         ,jlong pt
562                                                                                                                                                         ,jboolean enable) {
563         return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
564 }
565 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
566                                                                                                                                                         ,jobject  thiz
567                                                                                                                                                         ,jlong lc
568                                                                                                                                                         ,jboolean enable) {
569         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
570 }
571 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
572                                                                                                                                                         ,jobject  thiz
573                                                                                                                                                         ,jlong lc
574                                                                                                                                                         ) {
575         return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
576 }
577
578 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
579                                                                                                                                                         ,jobject  thiz
580                                                                                                                                                         ,jlong lc
581                                                                                                                                                         ) {
582         return (jlong)linphone_core_get_current_call((LinphoneCore*)lc);
583 }
584 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
585                                                                                                                                                         ,jobject  thiz
586                                                                                                                                                         ,jlong lc
587                                                                                                                                                         ,jlong aFriend
588                                                                                                                                                         ) {
589         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
590 }
591 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
592                                                                                                                                                         ,jobject  thiz
593                                                                                                                                                         ,jlong lc
594                                                                                                                                                         ,jint minute_away
595                                                                                                                                                         ,jstring jalternative_contact
596                                                                                                                                                         ,jint status) {
597         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
598         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
599         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
600 }
601
602 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
603                                                                                                                                                         ,jobject  thiz
604                                                                                                                                                         ,jlong lc
605                                                                                                                                                         ,jstring jto) {
606
607         const char* to = env->GetStringUTFChars(jto, NULL);
608         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
609         env->ReleaseStringUTFChars(jto, to);
610         return (long)lResult;
611 }
612
613 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
614                                                                                                                                                         ,jobject  thiz
615                                                                                                                                                         ,jlong lc
616                                                                                                                                                         ,jboolean vcap_enabled
617                                                                                                                                                         ,jboolean display_enabled) {
618         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
619
620 }
621 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
622                                                                                                                                                         ,jobject  thiz
623                                                                                                                                                         ,jlong lc) {
624         return linphone_core_video_enabled((LinphoneCore*)lc);
625 }
626 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
627                                                                                                                                                         ,jobject  thiz
628                                                                                                                                                         ,jlong lc
629                                                                                                                                                         ,jstring jpath) {
630         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
631         linphone_core_set_ring((LinphoneCore*)lc,path);
632         if (path) env->ReleaseStringUTFChars(jpath, path);
633 }
634 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
635                                                                                                                                                         ,jobject  thiz
636                                                                                                                                                         ,jlong lc
637                                                                                                                                                         ) {
638         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
639         if (path) {
640                 return env->NewStringUTF(path);
641         } else {
642                 return NULL;
643         }
644 }
645 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
646                                                                                                                                 ,jobject  thiz
647                                                                                                                                 ,jlong lc
648                                                                                                                                 ,jboolean enable) {
649         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
650
651 }
652 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
653                                                                                                                                 ,jobject  thiz
654                                                                                                                                 ,jlong lc) {
655         return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
656
657 }
658 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
659                                                                                                                                                                 ,jobject  thiz
660                                                                                                                                                                 ,jlong lc
661                                                                                                                                                                 ,jobject data) {
662         return linphone_core_start_echo_calibration((LinphoneCore*)lc
663                                                                                                         , LinphoneCoreData::ecCalibrationStatus
664                                                                                                         , data?env->NewGlobalRef(data):NULL);
665
666 }
667
668
669
670 //ProxyConfig
671
672 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
673         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
674         return  (jlong) proxy;
675 }
676
677 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
678         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
679 }
680 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
681         const char* identity = env->GetStringUTFChars(jidentity, NULL);
682         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
683         env->ReleaseStringUTFChars(jidentity, identity);
684 }
685 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
686         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
687         if (identity) {
688                 return env->NewStringUTF(identity);
689         } else {
690                 return NULL;
691         }
692 }
693 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
694         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
695         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
696         env->ReleaseStringUTFChars(jproxy, proxy);
697         return err;
698 }
699 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
700         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
701         if (proxy) {
702                 return env->NewStringUTF(proxy);
703         } else {
704                 return NULL;
705         }
706 }
707 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
708         if (jroute != NULL) {
709                 const char* route = env->GetStringUTFChars(jroute, NULL);
710                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
711                 env->ReleaseStringUTFChars(jroute, route);
712                 return err;
713         } else {
714                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
715         }
716 }
717 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
718         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
719         if (route) {
720                 return env->NewStringUTF(route);
721         } else {
722                 return NULL;
723         }
724 }
725
726 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
727         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
728 }
729 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
730         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
731 }
732 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
733         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
734 }
735 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
736         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
737 }
738 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
739         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
740 }
741 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
742         if (jnumber == 0) {
743                 ms_error("cannot normalized null number");
744         }
745         const char* number = env->GetStringUTFChars(jnumber, NULL);
746         int len = env->GetStringLength(jnumber);
747         if (len == 0) {
748                 ms_warning("cannot normalize empty number");
749                 return jnumber;
750         }
751         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
752         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
753         jstring normalizedNumber = env->NewStringUTF(targetBuff);
754         env->ReleaseStringUTFChars(jnumber, number);
755         return normalizedNumber;
756 }
757 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
758                                                                                                                                                         ,jobject thiz
759                                                                                                                                                         ,jlong proxyCfg) {
760         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
761         if (domain) {
762                 return env->NewStringUTF(domain);
763         } else {
764                 return NULL;
765         }
766 }
767 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
768         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
769 }
770
771 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
772                                                                                                                                         ,jobject thiz
773                                                                                                                                         ,jlong proxyCfg
774                                                                                                                                         ,jstring jprefix) {
775         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
776         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
777         env->ReleaseStringUTFChars(jprefix, prefix);
778 }
779 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
780                                                                                                                                                                 ,jobject thiz
781                                                                                                                                                                 ,jlong proxyCfg
782                                                                                                                                                                 ,jboolean val) {
783         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
784 }
785 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
786         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
787 }
788
789 //Auth Info
790
791 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
792                 , jobject thiz
793                 , jstring jusername
794                 , jstring juserid
795                 , jstring jpassword
796                 , jstring jha1
797                 , jstring jrealm) {
798
799         const char* username = env->GetStringUTFChars(jusername, NULL);
800         const char* password = env->GetStringUTFChars(jpassword, NULL);
801         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
802
803         env->ReleaseStringUTFChars(jusername, username);
804         env->ReleaseStringUTFChars(jpassword, password);
805         return auth;
806
807 }
808 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
809                 , jobject thiz
810                 , jlong ptr) {
811         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
812 }
813
814 //LinphoneAddress
815
816 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
817                                                                                                                                                                         ,jobject  thiz
818                                                                                                                                                                         ,jstring juri
819                                                                                                                                                                         ,jstring jdisplayName) {
820         const char* uri = env->GetStringUTFChars(juri, NULL);
821         LinphoneAddress* address = linphone_address_new(uri);
822         if (jdisplayName && address) {
823                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
824                 linphone_address_set_display_name(address,displayName);
825                 env->ReleaseStringUTFChars(jdisplayName, displayName);
826         }
827         env->ReleaseStringUTFChars(juri, uri);
828
829         return  (jlong) address;
830 }
831 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
832                                                                                                                                                 ,jobject  thiz
833                                                                                                                                                 ,jlong ptr) {
834         linphone_address_destroy((LinphoneAddress*)ptr);
835 }
836
837 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
838                                                                                                                                                 ,jobject  thiz
839                                                                                                                                                 ,jlong ptr) {
840         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
841         if (displayName) {
842                 return env->NewStringUTF(displayName);
843         } else {
844                 return 0;
845         }
846 }
847 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
848                                                                                                                                                 ,jobject  thiz
849                                                                                                                                                 ,jlong ptr) {
850         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
851         if (userName) {
852                 return env->NewStringUTF(userName);
853         } else {
854                 return 0;
855         }
856 }
857 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
858                                                                                                                                                 ,jobject  thiz
859                                                                                                                                                 ,jlong ptr) {
860         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
861         if (domain) {
862                 return env->NewStringUTF(domain);
863         } else {
864                 return 0;
865         }
866 }
867
868 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
869                                                                                                                                                 ,jobject  thiz
870                                                                                                                                                 ,jlong ptr) {
871         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
872         jstring juri =env->NewStringUTF(uri);
873         ms_free(uri);
874         return juri;
875 }
876 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
877                                                                                                                                                 ,jobject  thiz
878                                                                                                                                                 ,jlong ptr) {
879         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
880         jstring juri =env->NewStringUTF(uri);
881         ms_free(uri);
882         return juri;
883 }
884 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
885                                                                                                                                                 ,jobject  thiz
886                                                                                                                                                 ,jlong address
887                                                                                                                                                 ,jstring jdisplayName) {
888         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
889         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
890         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
891 }
892
893
894 //CallLog
895 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
896                                                                                                                                                 ,jobject  thiz
897                                                                                                                                                 ,jlong ptr) {
898         return (jlong)((LinphoneCallLog*)ptr)->from;
899 }
900 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
901                                                                                                                                                 ,jobject  thiz
902                                                                                                                                                 ,jlong ptr) {
903         return (jlong)((LinphoneCallLog*)ptr)->to;
904 }
905 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
906                                                                                                                                                 ,jobject  thiz
907                                                                                                                                                 ,jlong ptr) {
908         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
909 }
910
911 /*payloadType*/
912 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
913         PayloadType* pt = (PayloadType*)ptr;
914         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
915                                                                         ,payload_type_get_mime(pt)
916                                                                         ,payload_type_get_rate(pt)
917                                                                         ,payload_type_get_bitrate(pt));
918         jstring jvalue =env->NewStringUTF(value);
919         ms_free(value);
920         return jvalue;
921 }
922 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
923         PayloadType* pt = (PayloadType*)ptr;
924         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
925         return jvalue;
926 }
927 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
928         PayloadType* pt = (PayloadType*)ptr;
929         return payload_type_get_rate(pt);
930 }
931
932 //LinphoneCall
933 extern "C" void Java_org_linphone_core_LinphoneCallImpl_ref(JNIEnv*  env
934                                                                                                                                                 ,jobject  thiz
935                                                                                                                                                 ,jlong ptr) {
936         linphone_call_ref((LinphoneCall*)ptr);
937 }
938
939 extern "C" void Java_org_linphone_core_LinphoneCallImpl_unref(JNIEnv*  env
940                                                                                                                                                 ,jobject  thiz
941                                                                                                                                                 ,jlong ptr) {
942         linphone_call_unref((LinphoneCall*)ptr);
943 }
944
945 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
946                                                                                                                                                 ,jobject  thiz
947                                                                                                                                                 ,jlong ptr) {
948         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
949 }
950
951 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
952                                                                                                                                                 ,jobject  thiz
953                                                                                                                                                 ,jlong ptr) {
954         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
955 }
956
957 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
958                                                                                                                                                 ,jobject  thiz
959                                                                                                                                                 ,jlong ptr) {
960         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
961 }
962
963 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
964                                                                                                                                                 ,jobject  thiz
965                                                                                                                                                 ,jlong ptr) {
966         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
967 }
968 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
969                                                                                                                                                 ,jobject  thiz
970                                                                                                                                                 ,jlong ptr
971                                                                                                                                                 ,jboolean value) {
972         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
973 }
974 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
975                                                                                                                                                 ,jobject  thiz
976                                                                                                                                                 ,jlong ptr) {
977         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
978 }
979
980 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
981                                                                                                                                                 ,jobject  thiz
982                                                                                                                                                 ,jlong ptr
983                                                                                                                                                 ,jboolean value) {
984         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
985 }
986 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
987                                                                                                                                                 ,jobject  thiz
988                                                                                                                                                 ,jlong ptr) {
989         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
990 }
991
992
993 //LinphoneFriend
994 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
995                                                                                                                                                 ,jobject  thiz
996                                                                                                                                                 ,jstring jFriendUri) {
997         LinphoneFriend* lResult;
998
999         if (jFriendUri) {
1000                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1001                 lResult= linphone_friend_new_with_addr(friendUri);
1002                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1003         } else {
1004                 lResult = linphone_friend_new();
1005         }
1006         return (long)lResult;
1007 }
1008 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1009                                                                                                                                                 ,jobject  thiz
1010                                                                                                                                                 ,jlong ptr
1011                                                                                                                                                 ,jlong linphoneAddress) {
1012         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1013 }
1014 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1015                                                                                                                                                 ,jobject  thiz
1016                                                                                                                                                 ,jlong ptr) {
1017         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1018 }
1019 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1020                                                                                                                                                 ,jobject  thiz
1021                                                                                                                                                 ,jlong ptr
1022                                                                                                                                                 ,jint policy) {
1023         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1024 }
1025 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1026                                                                                                                                                 ,jobject  thiz
1027                                                                                                                                                 ,jlong ptr) {
1028         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1029 }
1030 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1031                                                                                                                                                 ,jobject  thiz
1032                                                                                                                                                 ,jlong ptr
1033                                                                                                                                                 ,jboolean value) {
1034         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1035 }
1036 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1037                                                                                                                                                 ,jobject  thiz
1038                                                                                                                                                 ,jlong ptr) {
1039         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1040 }
1041 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1042                                                                                                                                                 ,jobject  thiz
1043                                                                                                                                                 ,jlong ptr) {
1044         return linphone_friend_get_status((LinphoneFriend*)ptr);
1045 }
1046 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1047                                                                                                                                                 ,jobject  thiz
1048                                                                                                                                                 ,jlong ptr) {
1049         return linphone_friend_edit((LinphoneFriend*)ptr);
1050 }
1051 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1052                                                                                                                                                 ,jobject  thiz
1053                                                                                                                                                 ,jlong ptr) {
1054          linphone_friend_done((LinphoneFriend*)ptr);
1055 }
1056 //LinphoneChatRoom
1057 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1058                                                                                                                                                 ,jobject  thiz
1059                                                                                                                                                 ,jlong ptr) {
1060         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1061 }
1062 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1063                                                                                                                                                 ,jobject  thiz
1064                                                                                                                                                 ,jlong ptr
1065                                                                                                                                                 ,jstring jmessage) {
1066         const char* message = env->GetStringUTFChars(jmessage, NULL);
1067         linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
1068         env->ReleaseStringUTFChars(jmessage, message);
1069
1070 }
1071
1072 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1073                                                                                                                                                 ,jobject thiz
1074                                                                                                                                                 ,jlong lc
1075                                                                                                                                                 ,jobject obj) {
1076         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1077 }
1078
1079
1080 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1081         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1082 }
1083
1084 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1085         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1086 }
1087
1088 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1089         const char* server = NULL;
1090         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1091         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1092         if (server) env->ReleaseStringUTFChars(jserver,server);
1093 }
1094
1095 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1096         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1097         if (ret==NULL) return NULL;
1098         jstring jvalue =env->NewStringUTF(ret);
1099         return jvalue;
1100 }
1101
1102 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1103         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1104 }
1105
1106 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1107         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1108 }
1109
1110 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1111         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1112 }
1113 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1114         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1115 }
1116 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1117         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1118 }
1119
1120 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1121         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1122 }
1123
1124 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1125         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1126 }
1127
1128 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1129         return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
1130 }
1131
1132 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1133         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1134 }
1135
1136 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1137         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1138 }
1139
1140
1141 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1142         MSVideoSize vsize;
1143         vsize.width = (int)width;
1144         vsize.height = (int)height;
1145         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1146 }
1147
1148 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1149         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1150     jintArray arr = env->NewIntArray(2);
1151         int tVsize [2]= {vsize.width,vsize.height};
1152     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1153     return arr;
1154 }
1155
1156 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1157         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1158 }
1159
1160 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1161         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1162 }
1163 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1164         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1165 }
1166 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1167         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1168 }
1169