linphonecore_jni.cc 87.8 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
linphonecore_jni.cc
Copyright (C) 2010  Belledonne Communications, Grenoble, France

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#include <jni.h>
20
#ifdef USE_JAVAH
21
#include "linphonecore_jni.h"
22
#endif
jehan's avatar
jehan committed
23
#include "linphonecore_utils.h"
24
#include <ortp/zrtp.h>
jehan's avatar
jehan committed
25

Guillaume Beraudo's avatar
Guillaume Beraudo committed
26
#ifdef TUNNEL_ENABLED
jehan's avatar
jehan committed
27
#include "linphone_tunnel.h"
Guillaume Beraudo's avatar
Guillaume Beraudo committed
28 29
#endif

30 31 32
extern "C" {
#include "mediastreamer2/mediastream.h"
}
Simon Morlat's avatar
Simon Morlat committed
33
#include "mediastreamer2/msjava.h"
34
#include "private.h"
35 36
#include <cpu-features.h>

jehan's avatar
jehan committed
37 38
#ifdef ANDROID
#include <android/log.h>
39
extern "C" void libmsilbc_init();
40
#ifdef HAVE_X264
Simon Morlat's avatar
Simon Morlat committed
41
extern "C" void libmsx264_init();
42
#endif
Simon Morlat's avatar
Simon Morlat committed
43 44 45
#ifdef HAVE_AMR
extern "C" void libmsamr_init();
#endif
46 47 48
#ifdef HAVE_SILK
extern "C" void libmssilk_init();
#endif
jehan's avatar
jehan committed
49 50 51
#ifdef HAVE_G729
extern "C" void libmsbcg729_init();
#endif
jehan's avatar
jehan committed
52 53 54 55 56 57 58
#endif /*ANDROID*/

static JavaVM *jvm=0;

#ifdef ANDROID
static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
	int prio;
59 60 61
 	char str[4096];
	char *current;
	char *next;
jehan's avatar
jehan committed
62 63 64 65 66 67 68 69
	switch(lev){
	case ORTP_DEBUG:	prio = ANDROID_LOG_DEBUG;	break;
	case ORTP_MESSAGE:	prio = ANDROID_LOG_INFO;	break;
	case ORTP_WARNING:	prio = ANDROID_LOG_WARN;	break;
	case ORTP_ERROR:	prio = ANDROID_LOG_ERROR;	break;
	case ORTP_FATAL:	prio = ANDROID_LOG_FATAL;	break;
	default:		prio = ANDROID_LOG_DEFAULT;	break;
	}
70 71 72 73 74 75 76 77 78 79 80 81 82
 	vsnprintf(str, sizeof(str) - 1, fmt, args);
 	str[sizeof(str) - 1] = '\0';
 	if (strlen(str) < 512) {
		__android_log_write(prio, LOG_DOMAIN, str);
	} else {
		current = str;
		while ((next = strchr(current, '\n')) != NULL) {
			*next = '\0';
			__android_log_write(prio, LOG_DOMAIN, current);
			current = next + 1;
		}
		__android_log_write(prio, LOG_DOMAIN, current);
	}
jehan's avatar
jehan committed
83
}
84 85 86 87

int dumbMethodForAllowingUsageOfCpuFeaturesFromStaticLibMediastream() {
	return (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
}
jehan's avatar
jehan committed
88 89 90 91
#endif /*ANDROID*/

JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
{
jehan's avatar
jehan committed
92
#ifdef ANDROID
Simon Morlat's avatar
Simon Morlat committed
93
	ms_set_jvm(ajvm);
jehan's avatar
jehan committed
94 95 96 97 98 99
#endif /*ANDROID*/
	jvm=ajvm;
	return JNI_VERSION_1_2;
}


jehan's avatar
jehan committed
100
//LinphoneFactory
jehan's avatar
jehan committed
101
extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
jehan's avatar
jehan committed
102 103 104 105 106 107 108 109
		,jobject  thiz
		,jboolean isDebug) {
	if (isDebug) {
		linphone_core_enable_logs_with_cb(linphone_android_log_handler);
	} else {
		linphone_core_disable_logs();
	}
}
jehan's avatar
jehan committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
// LinphoneCore

class LinphoneCoreData {
public:
	LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {

		core = env->NewGlobalRef(lc);
		listener = env->NewGlobalRef(alistener);
		userdata = auserdata?env->NewGlobalRef(auserdata):0;
		memset(&vTable,0,sizeof(vTable));
		vTable.show = showInterfaceCb;
		vTable.auth_info_requested = authInfoRequested;
		vTable.display_status = displayStatusCb;
		vTable.display_message = displayMessageCb;
		vTable.display_warning = displayMessageCb;
125
		vTable.global_state_changed = globalStateChange;
jehan's avatar
jehan committed
126 127
		vTable.registration_state_changed = registrationStateChange;
		vTable.call_state_changed = callStateChange;
128
		vTable.call_encryption_changed = callEncryptionChange;
129
		vTable.text_received = text_received;
130
		vTable.message_received = message_received;
Sylvain Berfini's avatar
Sylvain Berfini committed
131
		vTable.dtmf_received = dtmf_received;
132 133
		vTable.new_subscription_request = new_subscription_request;
		vTable.notify_presence_recv = notify_presence_recv;
134
		vTable.call_stats_updated = callStatsUpdated;
jehan's avatar
jehan committed
135

136
		listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
137

jehan's avatar
jehan committed
138
		/*displayStatus(LinphoneCore lc,String message);*/
139
		displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
140

jehan's avatar
jehan committed
141
		/*void generalState(LinphoneCore lc,int state); */
142
		globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
143 144
		globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
		globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
145

146
		/*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
147
		registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
148 149
		registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
		registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
150

151
		/*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
152
		callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
153 154
		callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
		callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
155

156 157 158
		/*callStatsUpdated(LinphoneCore lc, LinphoneCall call, LinphoneCallStats stats);*/
		callStatsUpdatedId = env->GetMethodID(listenerClass, "callStatsUpdated", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCallStats;)V");

159 160 161
		chatMessageStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessage$State"));
		chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;");

162
		/*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
163
		callEncryptionChangedId=env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
164

jehan's avatar
jehan committed
165
		/*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
166
		ecCalibrationStatusId = env->GetMethodID(listenerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
jehan's avatar
jehan committed
167 168
		ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
		ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
169

170
		/*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
171
		newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
172 173

		/*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
174
		notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
175 176

		/*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
177
		textReceivedId = env->GetMethodID(listenerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
Simon Morlat's avatar
Simon Morlat committed
178
		messageReceivedId = env->GetMethodID(listenerClass,"messageReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneChatMessage;)V");
Sylvain Berfini's avatar
Sylvain Berfini committed
179
		dtmfReceivedId = env->GetMethodID(listenerClass,"dtmfReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;I)V");
180

181 182 183 184 185
		proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
		proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");

		callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
		callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
jehan's avatar
jehan committed
186

187
		chatMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessageImpl"));
Simon Morlat's avatar
Simon Morlat committed
188
		if (chatMessageClass) chatMessageCtrId = env->GetMethodID(chatMessageClass,"<init>", "(J)V");
189

190 191 192 193 194 195
		chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
		chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");

		friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
		friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");

jehan's avatar
jehan committed
196 197 198
		addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
		addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");

199 200 201 202
		callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl"));
		callStatsId = env->GetMethodID(callStatsClass, "<init>", "(JJ)V");
		callSetAudioStatsId = env->GetMethodID(callClass, "setAudioStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
		callSetVideoStatsId = env->GetMethodID(callClass, "setVideoStats", "(Lorg/linphone/core/LinphoneCallStats;)V");
jehan's avatar
jehan committed
203 204 205 206 207 208 209 210
	}

	~LinphoneCoreData() {
		JNIEnv *env = 0;
		jvm->AttachCurrentThread(&env,NULL);
		env->DeleteGlobalRef(core);
		env->DeleteGlobalRef(listener);
		if (userdata) env->DeleteGlobalRef(userdata);
211
		env->DeleteGlobalRef(listenerClass);
jehan's avatar
jehan committed
212 213 214
		env->DeleteGlobalRef(globalStateClass);
		env->DeleteGlobalRef(registrationStateClass);
		env->DeleteGlobalRef(callStateClass);
215
		env->DeleteGlobalRef(callStatsClass);
216
		env->DeleteGlobalRef(chatMessageStateClass);
jehan's avatar
jehan committed
217 218
		env->DeleteGlobalRef(proxyClass);
		env->DeleteGlobalRef(callClass);
219
		env->DeleteGlobalRef(chatMessageClass);
220 221
		env->DeleteGlobalRef(chatRoomClass);
		env->DeleteGlobalRef(friendClass);
jehan's avatar
jehan committed
222

jehan's avatar
jehan committed
223 224 225 226 227
	}
	jobject core;
	jobject listener;
	jobject userdata;

228
	jclass listenerClass;
jehan's avatar
jehan committed
229
	jmethodID displayStatusId;
230 231 232
	jmethodID newSubscriptionRequestId;
	jmethodID notifyPresenceReceivedId;
	jmethodID textReceivedId;
233
	jmethodID messageReceivedId;
Sylvain Berfini's avatar
Sylvain Berfini committed
234
	jmethodID dtmfReceivedId;
235
	jmethodID callStatsUpdatedId;
236 237 238 239 240 241 242 243 244 245 246 247 248

	jclass globalStateClass;
	jmethodID globalStateId;
	jmethodID globalStateFromIntId;

	jclass registrationStateClass;
	jmethodID registrationStateId;
	jmethodID registrationStateFromIntId;

	jclass callStateClass;
	jmethodID callStateId;
	jmethodID callStateFromIntId;

249 250 251 252 253
	jclass callStatsClass;
	jmethodID callStatsId;
	jmethodID callSetAudioStatsId;
	jmethodID callSetVideoStatsId;

254 255 256
	jclass chatMessageStateClass;
	jmethodID chatMessageStateFromIntId;

257 258
	jmethodID callEncryptionChangedId;

jehan's avatar
jehan committed
259 260 261 262
	jclass ecCalibratorStatusClass;
	jmethodID ecCalibrationStatusId;
	jmethodID ecCalibratorStatusFromIntId;

263 264 265 266 267 268
	jclass proxyClass;
	jmethodID proxyCtrId;

	jclass callClass;
	jmethodID callCtrId;

269 270 271
	jclass chatMessageClass;
	jmethodID chatMessageCtrId;

272 273 274 275 276 277
	jclass chatRoomClass;
	jmethodID chatRoomCtrId;

	jclass friendClass;
	jmethodID friendCtrId;

jehan's avatar
jehan committed
278 279 280
	jclass addressClass;
	jmethodID addressCtrId;

jehan's avatar
jehan committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
	LinphoneCoreVTable vTable;

	static void showInterfaceCb(LinphoneCore *lc) {

	}
	static void byeReceivedCb(LinphoneCore *lc, const char *from) {

	}
	static void displayStatusCb(LinphoneCore *lc, const char *message) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
Sylvain Berfini's avatar
Sylvain Berfini committed
297
		env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,message ? env->NewStringUTF(message) : NULL);
jehan's avatar
jehan committed
298 299 300 301 302 303 304
	}
	static void displayMessageCb(LinphoneCore *lc, const char *message) {

	}
	static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {

	}
305 306 307 308 309 310 311 312 313 314 315
	static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->globalStateId
							,lcData->core
jehan's avatar
jehan committed
316
							,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
317 318
							message ? env->NewStringUTF(message) : NULL);
	}
jehan's avatar
jehan committed
319
	static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
jehan's avatar
jehan committed
320 321 322 323 324 325 326 327
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
328
							,lcData->registrationStateId
jehan's avatar
jehan committed
329
							,lcData->core
jehan's avatar
jehan committed
330 331
							,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
							,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
332
							message ? env->NewStringUTF(message) : NULL);
jehan's avatar
jehan committed
333
	}
334 335 336 337 338 339 340 341
	jobject getCall(JNIEnv *env , LinphoneCall *call){
		jobject jobj=0;

		if (call!=NULL){
			void *up=linphone_call_get_user_pointer(call);
			
			if (up==NULL){
				jobj=env->NewObject(callClass,callCtrId,(jlong)call);
342
				jobj=env->NewGlobalRef(jobj);
343 344 345 346 347 348 349 350 351
				linphone_call_set_user_pointer(call,(void*)jobj);
				linphone_call_ref(call);
			}else{
				jobj=(jobject)up;
			}
		}
		return jobj;
	}

jehan's avatar
jehan committed
352
	static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
353 354
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
355
		jobject jcall;
356 357 358 359 360 361 362 363
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->callStateId
							,lcData->core
364
							,(jcall=lcData->getCall(env,call))
jehan's avatar
jehan committed
365
							,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
366
							message ? env->NewStringUTF(message) : NULL);
367 368 369 370
		if (state==LinphoneCallReleased){
			linphone_call_set_user_pointer(call,NULL);
			env->DeleteGlobalRef(jcall);
		}
371
	}
372 373 374 375 376 377 378 379 380 381 382
	static void callEncryptionChange(LinphoneCore *lc, LinphoneCall* call, bool_t encrypted,const char* authentication_token) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->callEncryptionChangedId
							,lcData->core
383
							,lcData->getCall(env,call)
384 385 386
							,encrypted
							,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
	}
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
	static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->notifyPresenceReceivedId
							,lcData->core
							,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
	}
	static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->newSubscriptionRequestId
							,lcData->core
							,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
							,url ? env->NewStringUTF(url) : NULL);
	}
Sylvain Berfini's avatar
Sylvain Berfini committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427
	static void dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->dtmfReceivedId
							,lcData->core
							,lcData->getCall(env,call)
							,dtmf);
	}
428 429 430 431 432 433 434 435 436 437 438 439
	static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->textReceivedId
							,lcData->core
							,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
jehan's avatar
jehan committed
440
							,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
441 442
							,message ? env->NewStringUTF(message) : NULL);
	}
Sylvain Berfini's avatar
Sylvain Berfini committed
443
	static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
444 445 446 447 448 449 450 451 452 453 454 455 456
			JNIEnv *env = 0;
			jint result = jvm->AttachCurrentThread(&env,NULL);
			if (result != 0) {
				ms_error("cannot attach VM\n");
				return;
			}
			LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
			env->CallVoidMethod(lcData->listener
								,lcData->messageReceivedId
								,lcData->core
								,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
								,env->NewObject(lcData->chatMessageClass,lcData->chatMessageCtrId,(jlong)msg));
		}
jehan's avatar
jehan committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
	static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		env->CallVoidMethod(lcData->listener
							,lcData->ecCalibrationStatusId
							,lcData->core
							,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
							,delay_ms
							,data ? data : NULL);
		if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
			//final state, releasing global ref
			env->DeleteGlobalRef((jobject)data);
		}

	}
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
	static void callStatsUpdated(LinphoneCore *lc, LinphoneCall* call, const LinphoneCallStats *stats) {
		JNIEnv *env = 0;
		jobject statsobj;
		jobject callobj;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM\n");
			return;
		}
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
		statsobj = env->NewObject(lcData->callStatsClass, lcData->callStatsId, (jlong)call, (jlong)stats);
		callobj = lcData->getCall(env, call);
		if (stats->type == LINPHONE_CALL_STATS_AUDIO)
			env->CallVoidMethod(callobj, lcData->callSetAudioStatsId, statsobj);
		else
			env->CallVoidMethod(callobj, lcData->callSetVideoStatsId, statsobj);
		env->CallVoidMethod(lcData->listener, lcData->callStatsUpdatedId, lcData->core, callobj, statsobj);
	}
495

jehan's avatar
jehan committed
496 497 498 499 500 501 502 503 504

};
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
		,jobject  thiz
		,jobject jlistener
		,jstring juserConfig
		,jstring jfactoryConfig
		,jobject  juserdata){

505 506
	const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
	const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
jehan's avatar
jehan committed
507
	LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
508

jehan's avatar
jehan committed
509 510
#ifdef HAVE_ILBC
	libmsilbc_init(); // requires an fpu
Simon Morlat's avatar
Simon Morlat committed
511
#endif
512
#ifdef HAVE_X264
Simon Morlat's avatar
Simon Morlat committed
513
	libmsx264_init();
Simon Morlat's avatar
Simon Morlat committed
514 515 516
#endif
#ifdef HAVE_AMR
	libmsamr_init();
517 518 519
#endif
#ifdef HAVE_SILK
	libmssilk_init();
jehan's avatar
jehan committed
520 521 522
#endif
#ifdef HAVE_G729
	libmsbcg729_init();
jehan's avatar
jehan committed
523
#endif
jehan's avatar
jehan committed
524 525 526 527 528 529 530 531 532
	jlong nativePtr = (jlong)linphone_core_new(	&ldata->vTable
			,userConfig
			,factoryConfig
			,ldata);
	//clear auth info list
	linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
	//clear existing proxy config
	linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);

533 534
	if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
	if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
jehan's avatar
jehan committed
535 536
	return nativePtr;
}
Ghislain MARY's avatar
Ghislain MARY committed
537
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
jehan's avatar
jehan committed
538 539 540 541 542 543 544
		,jobject  thiz
		,jlong lc) {
	LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
	linphone_core_destroy((LinphoneCore*)lc);
	delete lcData;
}

545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPrimaryContact(JNIEnv* env, jobject  thiz, jlong lc, jstring jdisplayname, jstring jusername) {
	const char* displayname = env->GetStringUTFChars(jdisplayname, NULL);
	const char* username = env->GetStringUTFChars(jusername, NULL);

	LinphoneAddress *parsed = linphone_core_get_primary_contact_parsed((LinphoneCore*)lc);
    if (parsed != NULL) {
        linphone_address_set_display_name(parsed, displayname);
        linphone_address_set_username(parsed, username);
        char *contact = linphone_address_as_string(parsed);
		linphone_core_set_primary_contact((LinphoneCore*)lc, contact);
	}

	env->ReleaseStringUTFChars(jdisplayname, displayname);
	env->ReleaseStringUTFChars(jusername, username);
}

Ghislain MARY's avatar
Ghislain MARY committed
561
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
jehan's avatar
jehan committed
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	linphone_core_clear_proxy_config((LinphoneCore*)lc);
}

extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jlong pc) {
	linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
}
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
	LinphoneProxyConfig *config=0;
	linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
	return (jlong)config;
}

579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigList(JNIEnv* env, jobject thiz, jlong lc) {
	const MSList* proxies = linphone_core_get_proxy_config_list((LinphoneCore*)lc);
	int proxyCount = ms_list_size(proxies);
	jlongArray jProxies = env->NewLongArray(proxyCount);
	jlong *jInternalArray = env->GetLongArrayElements(jProxies, NULL);

	for (int i = 0; i < proxyCount; i++ ) {
		jInternalArray[i] = (unsigned long) (proxies->data);
		proxies = proxies->next;
	}

	env->ReleaseLongArrayElements(jProxies, jInternalArray, 0);

	return jProxies;
}

Ghislain MARY's avatar
Ghislain MARY committed
595
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig(	JNIEnv*  env
jehan's avatar
jehan committed
596
		,jobject  thiz
jehan's avatar
jehan committed
597
		,jobject jproxyCfg
jehan's avatar
jehan committed
598 599
		,jlong lc
		,jlong pc) {
jehan's avatar
jehan committed
600
	LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
jehan's avatar
jehan committed
601
	linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
jehan's avatar
jehan committed
602

Ghislain MARY's avatar
Ghislain MARY committed
603
	return (jint)linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
jehan's avatar
jehan committed
604 605
}

Ghislain MARY's avatar
Ghislain MARY committed
606
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
jehan's avatar
jehan committed
607 608 609
	linphone_core_clear_all_auth_info((LinphoneCore*)lc);
}

610 611 612 613
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_refreshRegisters(JNIEnv* env, jobject thiz,jlong lc) {
	linphone_core_refresh_registers((LinphoneCore*)lc);
}

jehan's avatar
jehan committed
614 615 616 617 618 619 620 621 622 623 624
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jlong pc) {
	linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
}
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
	linphone_core_iterate((LinphoneCore*)lc);
}
625
extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_invite(	JNIEnv*  env
jehan's avatar
jehan committed
626 627 628 629
		,jobject  thiz
		,jlong lc
		,jstring juri) {
	const char* uri = env->GetStringUTFChars(juri, NULL);
630
	LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
jehan's avatar
jehan committed
631
	LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
jehan's avatar
jehan committed
632
	env->ReleaseStringUTFChars(juri, uri);
633
	return lcd->getCall(env,lCall);
jehan's avatar
jehan committed
634
}
635
extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddress(	JNIEnv*  env
jehan's avatar
jehan committed
636 637 638
		,jobject  thiz
		,jlong lc
		,jlong to) {
639 640
	LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
	return lcd->getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to));
jehan's avatar
jehan committed
641
}
jehan's avatar
jehan committed
642 643 644

extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(	JNIEnv*  env
		,jobject  thiz
645 646 647
		,jlong lc
		,jlong call) {
	linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
jehan's avatar
jehan committed
648
}
jehan's avatar
jehan committed
649

jehan's avatar
jehan committed
650 651 652
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
jehan's avatar
jehan committed
653
	return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
jehan's avatar
jehan committed
654
}
jehan's avatar
jehan committed
655 656 657
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
jehan's avatar
jehan committed
658

Ghislain MARY's avatar
Ghislain MARY committed
659
	return (jboolean)linphone_core_in_call((LinphoneCore*)lc);
jehan's avatar
jehan committed
660 661 662 663
}
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
jehan's avatar
jehan committed
664

Ghislain MARY's avatar
Ghislain MARY committed
665
	return (jboolean)linphone_core_inc_invite_pending((LinphoneCore*)lc);
jehan's avatar
jehan committed
666 667 668
}
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(	JNIEnv*  env
		,jobject  thiz
669 670
		,jlong lc
		,jlong call) {
jehan's avatar
jehan committed
671

672
	linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
jehan's avatar
jehan committed
673
}
jehan's avatar
jehan committed
674

675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallWithParams(JNIEnv *env,
		jobject thiz,
		jlong lc,
		jlong call,
		jlong params){
	linphone_core_accept_call_with_params((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
}

extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallUpdate(JNIEnv *env,
		jobject thiz,
		jlong lc,
		jlong call,
		jlong params){
	linphone_core_accept_call_update((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
}

extern "C" void Java_org_linphone_core_LinphoneCoreImpl_deferCallUpdate(JNIEnv *env,
		jobject thiz,
		jlong lc,
694
		jlong call){
695 696 697
	linphone_core_defer_call_update((LinphoneCore*)lc,(LinphoneCall*)call);
}

jehan's avatar
jehan committed
698 699 700 701 702 703 704 705 706
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jint position) {
		return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
}
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
707
		return (jint)ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
jehan's avatar
jehan committed
708
}
jehan's avatar
jehan committed
709 710 711 712 713 714
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jboolean isReachable) {
		linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
}
jehan's avatar
jehan committed
715

716 717 718
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isNetworkStateReachable(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
719
		return (jboolean)linphone_core_is_network_reachable((LinphoneCore*)lc);
720 721
}

722 723 724 725
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMicrophoneGain(JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jfloat gain) {
Sylvain Berfini's avatar
Sylvain Berfini committed
726
		linphone_core_set_mic_gain_db((LinphoneCore*)lc,gain);
727 728
}

jehan's avatar
jehan committed
729
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(	JNIEnv*  env
730 731 732
		,jobject  thiz
		,jlong lc
		,jfloat gain) {
jehan's avatar
jehan committed
733
		linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
734 735
}

Ghislain MARY's avatar
Ghislain MARY committed
736
extern "C" jfloat Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(	JNIEnv*  env
737 738
		,jobject  thiz
		,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
739
		return (jfloat)linphone_core_get_playback_gain_db((LinphoneCore*)lc);
740
}
jehan's avatar
jehan committed
741

jehan's avatar
jehan committed
742 743 744 745 746 747
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jboolean isMuted) {
		linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
}
jehan's avatar
jehan committed
748 749 750 751 752 753 754 755 756 757

extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jstring jurl) {
	const char* url = env->GetStringUTFChars(jurl, NULL);
	jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
	env->ReleaseStringUTFChars(jurl, url);
	return result;
}
jehan's avatar
jehan committed
758 759 760 761 762 763
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jchar dtmf) {
	linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
}
jehan's avatar
jehan committed
764 765 766 767
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(	JNIEnv*  env
		,jobject  thiz
		,jlong lc
		,jchar dtmf
Guillaume Beraudo's avatar
Guillaume Beraudo committed
768 769
		,jint duration) {
	linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
jehan's avatar
jehan committed
770 771 772 773 774 775 776
}
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
	linphone_core_stop_dtmf((LinphoneCore*)lc);
}

Ghislain MARY's avatar
Ghislain MARY committed
777
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMissedCallsCount(JNIEnv*  env
778 779
																		,jobject  thiz
																		,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
780
	return (jint)linphone_core_get_missed_calls_count((LinphoneCore*)lc);
781 782
}

783 784 785 786 787 788
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_resetMissedCallsCount(JNIEnv*  env
																		,jobject  thiz
																		,jlong lc) {
	linphone_core_reset_missed_calls_count((LinphoneCore*)lc);
}

789 790 791
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeCallLog(JNIEnv*  env
																		,jobject  thiz
																		,jlong lc, jlong log) {
Sylvain Berfini's avatar
Sylvain Berfini committed
792
	linphone_core_remove_call_log((LinphoneCore*)lc, (LinphoneCallLog*) log);
793 794
}

jehan's avatar
jehan committed
795 796 797 798 799
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
																		,jobject  thiz
																		,jlong lc) {
	linphone_core_clear_call_logs((LinphoneCore*)lc);
}
jehan's avatar
jehan committed
800 801 802
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted(	JNIEnv*  env
		,jobject  thiz
		,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
803
	return (jboolean)linphone_core_is_mic_muted((LinphoneCore*)lc);
jehan's avatar
jehan committed
804
}
jehan's avatar
jehan committed
805 806 807 808
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jstring jmime
809 810
																			,jint rate
																			,jint channels) {
jehan's avatar
jehan committed
811
	const char* mime = env->GetStringUTFChars(jmime, NULL);
812
	jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate,channels);
jehan's avatar
jehan committed
813 814 815
	env->ReleaseStringUTFChars(jmime, mime);
	return result;
}
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc) {
	const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
	int codecsCount = ms_list_size(codecs);
	jlongArray jCodecs = env->NewLongArray(codecsCount);
	jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);

	for (int i = 0; i < codecsCount; i++ ) {
		jInternalArray[i] = (unsigned long) (codecs->data);
		codecs = codecs->next;
	}

	env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);

	return jCodecs;
}

Simon Morlat's avatar
Simon Morlat committed
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc) {
	const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
	int codecsCount = ms_list_size(codecs);
	jlongArray jCodecs = env->NewLongArray(codecsCount);
	jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);

	for (int i = 0; i < codecsCount; i++ ) {
		jInternalArray[i] = (unsigned long) (codecs->data);
		codecs = codecs->next;
	}

	env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);

	return jCodecs;
}

Ghislain MARY's avatar
Ghislain MARY committed
852
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
jehan's avatar
jehan committed
853 854 855 856
																			,jobject  thiz
																			,jlong lc
																			,jlong pt
																			,jboolean enable) {
Ghislain MARY's avatar
Ghislain MARY committed
857
	return (jint)linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
jehan's avatar
jehan committed
858
}
jehan's avatar
jehan committed
859 860 861 862 863
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jboolean enable) {
	linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
Simon Morlat's avatar
Simon Morlat committed
864 865 866 867 868 869
}
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoLimiter(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jboolean enable) {
	linphone_core_enable_echo_limiter((LinphoneCore*)lc,enable);
jehan's avatar
jehan committed
870 871 872 873 874
}
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			) {
Ghislain MARY's avatar
Ghislain MARY committed
875
	return (jboolean)linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
jehan's avatar
jehan committed
876
}
jehan's avatar
jehan committed
877

878 879 880 881
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoLimiterEnabled(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			) {
Ghislain MARY's avatar
Ghislain MARY committed
882
	return (jboolean)linphone_core_echo_limiter_enabled((LinphoneCore*)lc);
883 884
}

885
extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
jehan's avatar
jehan committed
886 887 888
																			,jobject  thiz
																			,jlong lc
																			) {
889 890 891
	LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
	
	return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc));
jehan's avatar
jehan committed
892
}
893 894 895 896 897 898 899 900 901 902 903 904 905
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jlong aFriend
																			) {
	linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
}
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jint minute_away
																			,jstring jalternative_contact
																			,jint status) {
906
	const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
jehan's avatar
jehan committed
907
	linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
908
	if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
909
}
jehan's avatar
jehan committed
910

Ghislain MARY's avatar
Ghislain MARY committed
911
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
912 913 914 915 916 917 918
																			,jobject  thiz
																			,jlong lc
																			,jstring jto) {

	const char* to = env->GetStringUTFChars(jto, NULL);
	LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
	env->ReleaseStringUTFChars(jto, to);
Ghislain MARY's avatar
Ghislain MARY committed
919
	return (jlong)lResult;
920
}
jehan's avatar
jehan committed
921

922 923 924 925 926 927 928 929 930 931 932
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jboolean vcap_enabled
																			,jboolean display_enabled) {
	linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);

}
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
933
	return (jboolean)linphone_core_video_enabled((LinphoneCore*)lc);
934
}
935 936 937 938 939 940 941 942
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlayFile(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jstring jpath) {
	const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
	linphone_core_set_play_file((LinphoneCore*)lc,path);
	if (path) env->ReleaseStringUTFChars(jpath, path);
}
jehan's avatar
jehan committed
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jstring jpath) {
	const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
	linphone_core_set_ring((LinphoneCore*)lc,path);
	if (path) env->ReleaseStringUTFChars(jpath, path);
}
extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			) {
	const char* path = linphone_core_get_ring((LinphoneCore*)lc);
	if (path) {
		return env->NewStringUTF(path);
	} else {
		return NULL;
	}
}
962 963 964 965 966 967 968 969
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRootCA(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
																			,jstring jpath) {
	const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
	linphone_core_set_root_ca((LinphoneCore*)lc,path);
	if (path) env->ReleaseStringUTFChars(jpath, path);
}
jehan's avatar
jehan committed
970 971 972 973 974
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
																,jobject  thiz
																,jlong lc
																,jboolean enable) {
	linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
jehan's avatar
jehan committed
975

jehan's avatar
jehan committed
976 977 978 979
}
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
																,jobject  thiz
																,jlong lc) {
Ghislain MARY's avatar
Ghislain MARY committed
980
	return (jboolean)linphone_core_keep_alive_enabled((LinphoneCore*)lc);
981

jehan's avatar
jehan committed
982
}
jehan's avatar
jehan committed
983 984 985 986
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
																				,jobject  thiz
																				,jlong lc
																				,jobject data) {
Ghislain MARY's avatar
Ghislain MARY committed
987
	return (jint)linphone_core_start_echo_calibration((LinphoneCore*)lc
jehan's avatar
jehan committed
988 989 990 991 992
													, LinphoneCoreData::ecCalibrationStatus
													, data?env->NewGlobalRef(data):NULL);

}

Ghislain MARY's avatar
Ghislain MARY committed
993
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryption(JNIEnv*  env
994 995 996
																			,jobject  thiz
																			,jlong lc
																			) {
Ghislain MARY's avatar
Ghislain MARY committed
997
	return (jint)linphone_core_get_media_encryption((LinphoneCore*)lc);
998
}
999

1000 1001 1002
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryption(JNIEnv*  env
																			,jobject  thiz
																			,jlong lc
Ghislain MARY's avatar
Ghislain MARY committed
1003
																			,jint menc) {
1004 1005
	linphone_core_set_media_encryption((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
}
1006

1007
extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_mediaEncryptionSupported(JNIEnv*  env
1008
																			,jobject  thiz
1009
																			,jlong lc, jint menc
1010
																			) {
Ghislain MARY's avatar
Ghislain MARY committed
1011
	return (jboolean)linphone_core_media_encryption_supported((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);