3 Copyright (C) 2010 Belledonne Communications, Grenoble, France
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.
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.
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.
20 #include "linphonecore_utils.h"
22 #include "mediastreamer2/msjava.h"
25 #include <android/log.h>
26 extern "C" void libmsilbc_init();
27 extern "C" void libmsx264_init();
33 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
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;
43 __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
47 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved)
53 return JNI_VERSION_1_2;
58 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv* env
62 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
64 linphone_core_disable_logs();
69 class LinphoneCoreData {
71 LinphoneCoreData(JNIEnv* env, jobject lc,jobject alistener, jobject auserdata) {
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;
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");
111 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
112 notifyPresenceReceivedId = env->GetMethodID(listernerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
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");
117 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
118 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
120 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
121 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
123 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
124 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
126 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
127 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
129 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
130 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
134 ~LinphoneCoreData() {
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);
154 jclass listernerClass;
155 jmethodID displayStatusId;
156 jmethodID newSubscriptionRequestId;
157 jmethodID notifyPresenceReceivedId;
158 jmethodID textReceivedId;
160 jclass globalStateClass;
161 jmethodID globalStateId;
162 jmethodID globalStateFromIntId;
164 jclass registrationStateClass;
165 jmethodID registrationStateId;
166 jmethodID registrationStateFromIntId;
168 jclass callStateClass;
169 jmethodID callStateId;
170 jmethodID callStateFromIntId;
172 jclass ecCalibratorStatusClass;
173 jmethodID ecCalibrationStatusId;
174 jmethodID ecCalibratorStatusFromIntId;
177 jmethodID proxyCtrId;
182 jclass chatRoomClass;
183 jmethodID chatRoomCtrId;
186 jmethodID friendCtrId;
189 jmethodID addressCtrId;
191 LinphoneCoreVTable vTable;
193 static void showInterfaceCb(LinphoneCore *lc) {
196 static void byeReceivedCb(LinphoneCore *lc, const char *from) {
199 static void displayStatusCb(LinphoneCore *lc, const char *message) {
201 jint result = jvm->AttachCurrentThread(&env,NULL);
203 ms_error("cannot attach VM\n");
206 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
207 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
209 static void displayMessageCb(LinphoneCore *lc, const char *message) {
212 static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
215 static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
217 jint result = jvm->AttachCurrentThread(&env,NULL);
219 ms_error("cannot attach VM\n");
222 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
223 env->CallVoidMethod(lcData->listener
224 ,lcData->globalStateId
226 ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
227 message ? env->NewStringUTF(message) : NULL);
229 static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
231 jint result = jvm->AttachCurrentThread(&env,NULL);
233 ms_error("cannot attach VM\n");
236 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
237 env->CallVoidMethod(lcData->listener
238 ,lcData->registrationStateId
240 ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
241 ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
242 message ? env->NewStringUTF(message) : NULL);
244 static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
246 jint result = jvm->AttachCurrentThread(&env,NULL);
248 ms_error("cannot attach VM\n");
251 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
252 env->CallVoidMethod(lcData->listener
255 ,env->NewObject(lcData->callClass,lcData->callCtrId,(jlong)call)
256 ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
257 message ? env->NewStringUTF(message) : NULL);
259 static void notify_presence_recv (LinphoneCore *lc, LinphoneFriend *my_friend) {
261 jint result = jvm->AttachCurrentThread(&env,NULL);
263 ms_error("cannot attach VM\n");
266 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
267 env->CallVoidMethod(lcData->listener
268 ,lcData->notifyPresenceReceivedId
270 ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
272 static void new_subscription_request (LinphoneCore *lc, LinphoneFriend *my_friend, const char* url) {
274 jint result = jvm->AttachCurrentThread(&env,NULL);
276 ms_error("cannot attach VM\n");
279 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
280 env->CallVoidMethod(lcData->listener
281 ,lcData->newSubscriptionRequestId
283 ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
284 ,url ? env->NewStringUTF(url) : NULL);
286 static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
288 jint result = jvm->AttachCurrentThread(&env,NULL);
290 ms_error("cannot attach VM\n");
293 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
294 env->CallVoidMethod(lcData->listener
295 ,lcData->textReceivedId
297 ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
298 ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
299 ,message ? env->NewStringUTF(message) : NULL);
301 static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
303 jint result = jvm->AttachCurrentThread(&env,NULL);
305 ms_error("cannot attach VM\n");
308 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
309 env->CallVoidMethod(lcData->listener
310 ,lcData->ecCalibrationStatusId
312 ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
314 ,data ? data : NULL);
315 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
316 //final state, releasing global ref
317 env->DeleteGlobalRef((jobject)data);
324 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv* env
328 ,jstring jfactoryConfig
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);
336 libmsilbc_init(); // requires an fpu
341 jlong nativePtr = (jlong)linphone_core_new( &ldata->vTable
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);
350 if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
351 if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
354 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv* env
357 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
358 linphone_core_destroy((LinphoneCore*)lc);
362 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
363 linphone_core_clear_proxy_config((LinphoneCore*)lc);
366 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig( JNIEnv* env
370 linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
372 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv* env
375 LinphoneProxyConfig *config=0;
376 linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
377 return (jlong)config;
380 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig( JNIEnv* env
385 LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
386 linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
388 return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
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);
395 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo( JNIEnv* env
399 linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
401 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate( JNIEnv* env
404 linphone_core_iterate((LinphoneCore*)lc);
406 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_invite( JNIEnv* env
410 const char* uri = env->GetStringUTFChars(juri, NULL);
411 LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
412 env->ReleaseStringUTFChars(juri, uri);
415 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddress( JNIEnv* env
419 return (jlong) linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to);
422 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall( JNIEnv* env
426 linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
429 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress( JNIEnv* env
432 return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
434 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall( JNIEnv* env
438 return linphone_core_in_call((LinphoneCore*)lc);
440 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending( JNIEnv* env
444 return linphone_core_inc_invite_pending((LinphoneCore*)lc);
446 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall( JNIEnv* env
451 linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
454 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog( JNIEnv* env
458 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
460 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs( JNIEnv* env
463 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
465 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable( JNIEnv* env
468 ,jboolean isReachable) {
469 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
472 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain( JNIEnv* env
476 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
479 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain( JNIEnv* env
482 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
485 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic( JNIEnv* env
489 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
492 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl( JNIEnv* env
496 const char* url = env->GetStringUTFChars(jurl, NULL);
497 jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
498 env->ReleaseStringUTFChars(jurl, url);
501 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf( JNIEnv* env
505 linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
507 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf( JNIEnv* env
513 linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration,speaker);
515 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf( JNIEnv* env
518 linphone_core_stop_dtmf((LinphoneCore*)lc);
521 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv* env
524 linphone_core_clear_call_logs((LinphoneCore*)lc);
526 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv* env
529 return linphone_core_is_mic_muted((LinphoneCore*)lc);
531 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv* env
536 const char* mime = env->GetStringUTFChars(jmime, NULL);
537 jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
538 env->ReleaseStringUTFChars(jmime, mime);
541 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv* env
544 const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
545 int codecsCount = ms_list_size(codecs);
546 jlongArray jCodecs = env->NewLongArray(codecsCount);
547 jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
549 for (int i = 0; i < codecsCount; i++ ) {
550 jInternalArray[i] = (unsigned long) (codecs->data);
551 codecs = codecs->next;
554 env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
559 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv* env
564 return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
566 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv* env
570 linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
572 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv* env
576 return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
579 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv* env
583 return (jlong)linphone_core_get_current_call((LinphoneCore*)lc);
585 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env
590 linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
592 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv* env
596 ,jstring jalternative_contact
598 const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
599 linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
600 if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
603 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv* env
608 const char* to = env->GetStringUTFChars(jto, NULL);
609 LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
610 env->ReleaseStringUTFChars(jto, to);
611 return (long)lResult;
614 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv* env
617 ,jboolean vcap_enabled
618 ,jboolean display_enabled) {
619 linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
622 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv* env
625 return linphone_core_video_enabled((LinphoneCore*)lc);
627 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv* env
631 const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
632 linphone_core_set_ring((LinphoneCore*)lc,path);
633 if (path) env->ReleaseStringUTFChars(jpath, path);
635 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv* env
639 const char* path = linphone_core_get_ring((LinphoneCore*)lc);
641 return env->NewStringUTF(path);
646 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv* env
650 linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
653 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv* env
656 return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
659 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv* env
663 return linphone_core_start_echo_calibration((LinphoneCore*)lc
664 , LinphoneCoreData::ecCalibrationStatus
665 , data?env->NewGlobalRef(data):NULL);
673 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv* env,jobject thiz) {
674 LinphoneProxyConfig* proxy = linphone_proxy_config_new();
675 return (jlong) proxy;
678 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv* env,jobject thiz,jlong ptr) {
679 linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
681 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
682 const char* identity = env->GetStringUTFChars(jidentity, NULL);
683 linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
684 env->ReleaseStringUTFChars(jidentity, identity);
686 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
687 const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
689 return env->NewStringUTF(identity);
694 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
695 const char* proxy = env->GetStringUTFChars(jproxy, NULL);
696 int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
697 env->ReleaseStringUTFChars(jproxy, proxy);
700 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
701 const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
703 return env->NewStringUTF(proxy);
708 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
709 if (jroute != NULL) {
710 const char* route = env->GetStringUTFChars(jroute, NULL);
711 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
712 env->ReleaseStringUTFChars(jroute, route);
715 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
718 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
719 const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
721 return env->NewStringUTF(route);
727 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
728 linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
730 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
731 return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
733 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
734 return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
736 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
737 linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
739 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
740 linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
742 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
744 ms_error("cannot normalized null number");
746 const char* number = env->GetStringUTFChars(jnumber, NULL);
747 int len = env->GetStringLength(jnumber);
749 ms_warning("cannot normalize empty number");
752 char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
753 linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
754 jstring normalizedNumber = env->NewStringUTF(targetBuff);
755 env->ReleaseStringUTFChars(jnumber, number);
756 return normalizedNumber;
758 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
761 const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
763 return env->NewStringUTF(domain);
768 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
769 linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
772 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
776 const char* prefix = env->GetStringUTFChars(jprefix, NULL);
777 linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
778 env->ReleaseStringUTFChars(jprefix, prefix);
780 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
784 linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
786 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
787 return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
792 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
800 const char* username = env->GetStringUTFChars(jusername, NULL);
801 const char* password = env->GetStringUTFChars(jpassword, NULL);
802 jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
804 env->ReleaseStringUTFChars(jusername, username);
805 env->ReleaseStringUTFChars(jpassword, password);
809 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
812 linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
817 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv* env
820 ,jstring jdisplayName) {
821 const char* uri = env->GetStringUTFChars(juri, NULL);
822 LinphoneAddress* address = linphone_address_new(uri);
823 if (jdisplayName && address) {
824 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
825 linphone_address_set_display_name(address,displayName);
826 env->ReleaseStringUTFChars(jdisplayName, displayName);
828 env->ReleaseStringUTFChars(juri, uri);
830 return (jlong) address;
832 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv* env
835 linphone_address_destroy((LinphoneAddress*)ptr);
838 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv* env
841 const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
843 return env->NewStringUTF(displayName);
848 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv* env
851 const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
853 return env->NewStringUTF(userName);
858 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv* env
861 const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
863 return env->NewStringUTF(domain);
869 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv* env
872 char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
873 jstring juri =env->NewStringUTF(uri);
877 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv* env
880 char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
881 jstring juri =env->NewStringUTF(uri);
885 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv* env
888 ,jstring jdisplayName) {
889 const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
890 linphone_address_set_display_name((LinphoneAddress*)address,displayName);
891 if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
896 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv* env
899 return (jlong)((LinphoneCallLog*)ptr)->from;
901 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv* env
904 return (jlong)((LinphoneCallLog*)ptr)->to;
906 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv* env
909 return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
913 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv* env,jobject thiz,jlong ptr) {
914 PayloadType* pt = (PayloadType*)ptr;
915 char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
916 ,payload_type_get_mime(pt)
917 ,payload_type_get_rate(pt)
918 ,payload_type_get_bitrate(pt));
919 jstring jvalue =env->NewStringUTF(value);
923 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv* env,jobject thiz,jlong ptr) {
924 PayloadType* pt = (PayloadType*)ptr;
925 jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
928 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv* env,jobject thiz, jlong ptr) {
929 PayloadType* pt = (PayloadType*)ptr;
930 return payload_type_get_rate(pt);
934 extern "C" void Java_org_linphone_core_LinphoneCallImpl_ref(JNIEnv* env
937 linphone_call_ref((LinphoneCall*)ptr);
940 extern "C" void Java_org_linphone_core_LinphoneCallImpl_unref(JNIEnv* env
943 linphone_call_unref((LinphoneCall*)ptr);
946 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog( JNIEnv* env
949 return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
952 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv* env
955 return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
958 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress( JNIEnv* env
961 return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
964 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState( JNIEnv* env
967 return (jint)linphone_call_get_state((LinphoneCall*)ptr);
969 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv* env
973 linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
975 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled( JNIEnv* env
978 return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
981 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter( JNIEnv* env
985 linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
987 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled( JNIEnv* env
990 return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
993 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getReplacedCall( JNIEnv* env
996 return (jlong)linphone_call_get_replaced_call((LinphoneCall*)ptr);
1001 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv* env
1003 ,jstring jFriendUri) {
1004 LinphoneFriend* lResult;
1007 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1008 lResult= linphone_friend_new_with_addr(friendUri);
1009 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1011 lResult = linphone_friend_new();
1013 return (long)lResult;
1015 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv* env
1018 ,jlong linphoneAddress) {
1019 linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1021 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv* env
1024 return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1026 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv* env
1030 linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1032 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv* env
1035 return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1037 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv* env
1041 linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1043 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv* env
1046 return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1048 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv* env
1051 return linphone_friend_get_status((LinphoneFriend*)ptr);
1053 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv* env
1056 return linphone_friend_edit((LinphoneFriend*)ptr);
1058 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv* env
1061 linphone_friend_done((LinphoneFriend*)ptr);
1064 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv* env
1067 return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1069 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv* env
1072 ,jstring jmessage) {
1073 const char* message = env->GetStringUTFChars(jmessage, NULL);
1074 linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
1075 env->ReleaseStringUTFChars(jmessage, message);
1079 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1083 linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1087 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1088 linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1091 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1092 return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1095 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1096 const char* server = NULL;
1097 if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1098 linphone_core_set_stun_server((LinphoneCore*)lc,server);
1099 if (server) env->ReleaseStringUTFChars(jserver,server);
1102 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1103 const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1104 if (ret==NULL) return NULL;
1105 jstring jvalue =env->NewStringUTF(ret);
1109 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1110 linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1113 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1114 linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1117 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1118 return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1120 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1121 return linphone_call_params_destroy((LinphoneCallParams*)lc);
1123 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1124 return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1127 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1128 return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1131 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1132 linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1135 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1136 return (jlong) linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params);
1139 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1140 return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1143 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1144 return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1148 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1150 vsize.width = (int)width;
1151 vsize.height = (int)height;
1152 linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1155 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1156 MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1157 jintArray arr = env->NewIntArray(2);
1158 int tVsize [2]= {vsize.width,vsize.height};
1159 env->SetIntArrayRegion(arr, 0, 2, tVsize);
1163 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1164 linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1167 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1168 linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1170 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv* env,jobject thiz,jlong ptr) {
1171 return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1173 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv* env,jobject thiz,jlong ptr,jint delay) {
1174 linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);