linphonecore_jni.cc 230 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 <mediastreamer2/zrtp.h>
jehan's avatar
jehan committed
25

Guillaume Beraudo's avatar
Guillaume Beraudo committed
26

27
28
extern "C" {
#include "mediastreamer2/mediastream.h"
29
#include "mediastreamer2/mscommon.h"
François Grisez's avatar
François Grisez committed
30
#include "mediastreamer2/msmediaplayer.h"
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
31
#include "mediastreamer2/msutils.h"
32
}
Simon Morlat's avatar
Simon Morlat committed
33
#include "mediastreamer2/msjava.h"
34
#include "private.h"
35
36
#include <cpu-features.h>

37
38
#include "lpconfig.h"

jehan's avatar
jehan committed
39
40
#ifdef ANDROID
#include <android/log.h>
Sylvain Berfini's avatar
Sylvain Berfini committed
41
extern "C" void libmsilbc_init();
42
#ifdef HAVE_X264
Simon Morlat's avatar
Simon Morlat committed
43
extern "C" void libmsx264_init();
44
#endif
45
46
47
#ifdef HAVE_OPENH264
extern "C" void libmsopenh264_init();
#endif
Simon Morlat's avatar
Simon Morlat committed
48
49
50
#ifdef HAVE_AMR
extern "C" void libmsamr_init();
#endif
51
52
53
#ifdef HAVE_SILK
extern "C" void libmssilk_init();
#endif
jehan's avatar
jehan committed
54
55
56
#ifdef HAVE_G729
extern "C" void libmsbcg729_init();
#endif
57
58
#ifdef HAVE_WEBRTC
extern "C" void libmswebrtc_init();
59
#endif
60
#include <belle-sip/wakelock.h>
jehan's avatar
jehan committed
61
62
#endif /*ANDROID*/

63
64
/*force linking of ms_audio_diff symbol because the tester requires it.*/
static void *audiodiff=(void*)&ms_audio_diff;
Ghislain MARY's avatar
Ghislain MARY committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#define RETURN_USER_DATA_OBJECT(javaclass, funcprefix, cobj) \
	{ \
		jclass jUserDataObjectClass; \
		jmethodID jUserDataObjectCtor; \
		jobject jUserDataObj; \
		jUserDataObj = (jobject)funcprefix ## _get_user_data(cobj); \
		if (jUserDataObj == NULL) { \
			jUserDataObjectClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/" javaclass)); \
			jUserDataObjectCtor = env->GetMethodID(jUserDataObjectClass,"<init>", "(J)V"); \
			jUserDataObj = env->NewObject(jUserDataObjectClass, jUserDataObjectCtor, (jlong)funcprefix ## _ref(cobj)); \
			jUserDataObj = env->NewGlobalRef(jUserDataObj); \
			funcprefix ## _set_user_data(cobj, jUserDataObj); \
			env->DeleteGlobalRef(jUserDataObjectClass); \
		} \
		return jUserDataObj; \
	}

jehan's avatar
jehan committed
83
static JavaVM *jvm=0;
84
static const char* LogDomain = "Linphone";
85
86
87
static jclass handler_class;
static jmethodID loghandler_id;
static jobject handler_obj=NULL;
jehan's avatar
jehan committed
88

89
90
static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent *content);

jehan's avatar
jehan committed
91
#ifdef ANDROID
92
void linphone_android_log_handler(int prio, char *str) {
93
94
	char *current;
	char *next;
95
96

	if (strlen(str) < 512) {
97
		__android_log_write(prio, LogDomain, str);
98
99
100
101
	} else {
		current = str;
		while ((next = strchr(current, '\n')) != NULL) {
			*next = '\0';
102
			__android_log_write(prio, LogDomain, current);
103
104
			current = next + 1;
		}
105
		__android_log_write(prio, LogDomain, current);
106
	}
jehan's avatar
jehan committed
107
}
108

109
static void linphone_android_ortp_log_handler(OrtpLogLevel lev, const char *fmt, va_list args) {
110
111
112
113
	char str[4096];
	const char *levname="undef";
	vsnprintf(str, sizeof(str) - 1, fmt, args);
	str[sizeof(str) - 1] = '\0';
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
114

115
116
	int prio;
	switch(lev){
117
118
119
120
121
122
	case ORTP_DEBUG:	prio = ANDROID_LOG_DEBUG;	levname="debug"; break;
	case ORTP_MESSAGE:	prio = ANDROID_LOG_INFO;	levname="message"; break;
	case ORTP_WARNING:	prio = ANDROID_LOG_WARN;	levname="warning"; break;
	case ORTP_ERROR:	prio = ANDROID_LOG_ERROR;	levname="error"; break;
	case ORTP_FATAL:	prio = ANDROID_LOG_FATAL;	levname="fatal"; break;
	default:			prio = ANDROID_LOG_DEFAULT;	break;
123
	}
124
125
	if (handler_obj){
		JNIEnv *env=ms_get_jni_env();
126
127
128
129
130
131
132
		jstring jdomain=env->NewStringUTF(LogDomain);
		jstring jlevname=env->NewStringUTF(levname);
		jstring jstr=env->NewStringUTF(str);
		env->CallVoidMethod(handler_obj,loghandler_id,jdomain,(jint)lev,jlevname,jstr,NULL);
		if (jdomain) env->DeleteLocalRef(jdomain);
		if (jlevname) env->DeleteLocalRef(jlevname);
		if (jstr) env->DeleteLocalRef(jstr);
133
134
	}else
		linphone_android_log_handler(prio, str);
135
136
}

137
138
139
int dumbMethodForAllowingUsageOfCpuFeaturesFromStaticLibMediastream() {
	return (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
}
jehan's avatar
jehan committed
140
141
142
143
#endif /*ANDROID*/

JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
{
jehan's avatar
jehan committed
144
#ifdef ANDROID
Simon Morlat's avatar
Simon Morlat committed
145
	ms_set_jvm(ajvm);
jehan's avatar
jehan committed
146
147
148
149
150
151
#endif /*ANDROID*/
	jvm=ajvm;
	return JNI_VERSION_1_2;
}


jehan's avatar
jehan committed
152
//LinphoneFactory
jehan's avatar
jehan committed
153
extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
jehan's avatar
jehan committed
154
		,jobject  thiz
155
156
		,jboolean isDebug
		,jstring  jdebugTag) {
jehan's avatar
jehan committed
157
	if (isDebug) {
158
		LogDomain = env->GetStringUTFChars(jdebugTag, NULL);
159
		linphone_core_enable_logs_with_cb(linphone_android_ortp_log_handler);
jehan's avatar
jehan committed
160
161
162
163
	} else {
		linphone_core_disable_logs();
	}
}
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_enableLogCollection(JNIEnv* env
		,jobject  thiz
		,jboolean enable) {
	linphone_core_enable_log_collection(enable ? LinphoneLogCollectionEnabledWithoutPreviousLogHandler : LinphoneLogCollectionDisabled);
}

extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setLogCollectionPath(JNIEnv* env
		,jobject  thiz
		,jstring jpath) {

	const char* path = env->GetStringUTFChars(jpath, NULL);
	linphone_core_set_log_collection_path(path);
	env->ReleaseStringUTFChars(jpath, path);
}
jehan's avatar
jehan committed
179
180
// LinphoneCore

181
182
183
184
185
186
187
/*
 * returns the java LinphoneProxyConfig associated with a C LinphoneProxyConfig.
**/
jobject getProxy(JNIEnv *env, LinphoneProxyConfig *proxy, jobject core){
	jobject jobj=0;

	if (proxy!=NULL){
188
		jclass proxyClass = (jclass)env->FindClass("org/linphone/core/LinphoneProxyConfigImpl");
189
		jmethodID proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(Lorg/linphone/core/LinphoneCoreImpl;J)V");
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
		void *up=linphone_proxy_config_get_user_data(proxy);

		if (up==NULL){
			jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy);
			linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj));
			linphone_proxy_config_ref(proxy);
		}else{
			//promote the weak ref to local ref
			jobj=env->NewLocalRef((jobject)up);
			if (jobj == NULL){
				//the weak ref was dead
				jobj=env->NewObject(proxyClass,proxyCtrId,core,(jlong)proxy);
				linphone_proxy_config_set_user_data(proxy,(void*)env->NewWeakGlobalRef(jobj));
			}
		}
206
		env->DeleteLocalRef(proxyClass);
207
208
209
210
211
212
213
214
	}
	return jobj;
}

jobject getCall(JNIEnv *env, LinphoneCall *call){
	jobject jobj=0;

	if (call!=NULL){
215
		jclass callClass = (jclass)env->FindClass("org/linphone/core/LinphoneCallImpl");
216
		jmethodID callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
217

218
219
220
221
222
223
224
225
226
227
		void *up=linphone_call_get_user_pointer(call);

		if (up==NULL){
			jobj=env->NewObject(callClass,callCtrId,(jlong)call);
			jobj=env->NewGlobalRef(jobj);
			linphone_call_set_user_pointer(call,(void*)jobj);
			linphone_call_ref(call);
		}else{
			jobj=(jobject)up;
		}
228
		env->DeleteLocalRef(callClass);
229
230
231
232
233
234
235
236
	}
	return jobj;
}

jobject getChatMessage(JNIEnv *env, LinphoneChatMessage *msg){
	jobject jobj = 0;

	if (msg != NULL){
237
		jclass chatMessageClass = (jclass)env->FindClass("org/linphone/core/LinphoneChatMessageImpl");
238
		jmethodID chatMessageCtrId = env->GetMethodID(chatMessageClass,"<init>", "(J)V");
239

240
241
242
243
244
245
246
247
248
		void *up = linphone_chat_message_get_user_data(msg);

		if (up == NULL) {
			jobj = env->NewObject(chatMessageClass,chatMessageCtrId,(jlong)linphone_chat_message_ref(msg));
			jobj = env->NewGlobalRef(jobj);
			linphone_chat_message_set_user_data(msg,(void*)jobj);
		} else {
			jobj = (jobject)up;
		}
249
		env->DeleteLocalRef(chatMessageClass);
250
251
252
253
254
255
256
257
	}
	return jobj;
}

jobject getEvent(JNIEnv *env, LinphoneEvent *lev){
	if (lev==NULL) return NULL;
	jobject jev=(jobject)linphone_event_get_user_data(lev);
	if (jev==NULL){
258
		jclass linphoneEventClass = (jclass)env->FindClass("org/linphone/core/LinphoneEventImpl");
259
		jmethodID linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"<init>", "(J)V");
260

261
262
263
		jev=env->NewObject(linphoneEventClass,linphoneEventCtrId,(jlong)linphone_event_ref(lev));
		jev=env->NewGlobalRef(jev);
		linphone_event_set_user_data(lev,jev);
264

265
		env->DeleteLocalRef(linphoneEventClass);
266
267
268
269
	}
	return jev;
}

jehan's avatar
jehan committed
270
271
class LinphoneCoreData {
public:
272
	LinphoneCoreData(JNIEnv *env, jobject lc, LinphoneCoreVTable *vTable, jobject alistener) {
jehan's avatar
jehan committed
273
274
		core = env->NewGlobalRef(lc);
		listener = env->NewGlobalRef(alistener);
275

276
		memset(vTable, 0, sizeof(LinphoneCoreVTable));
277

278
		listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass(alistener));
279

jehan's avatar
jehan committed
280
		/*displayStatus(LinphoneCore lc,String message);*/
281
		displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
282
283
284
		if (displayStatusId) {
			vTable->display_status = displayStatusCb;
		}
285

jehan's avatar
jehan committed
286
		/*void generalState(LinphoneCore lc,int state); */
287
288
		globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
		globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
289
		globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
290
291
292
		if (globalStateId) {
			vTable->global_state_changed = globalStateChange;
		}
293

294
295
296
		/*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
		registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
		registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
297
		registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
298
299
300
		if (registrationStateId) {
			vTable->registration_state_changed = registrationStateChange;
		}
301

302
303
304
		/*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
		callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
		callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
305
		callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
306
307
308
		if (callStateId) {
			vTable->call_state_changed = callStateChange;
		}
309

310
		transferStateId = env->GetMethodID(listenerClass,"transferState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;)V");
311
312
313
		if (transferStateId) {
			vTable->transfer_state_changed = transferStateChanged;
		}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
314

315
316
		/*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");
317
318
319
		if (callStatsUpdatedId) {
			vTable->call_stats_updated = callStatsUpdated;
		}
320

321
		/*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
322
323
324
325
		callEncryptionChangedId = env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
		if (callEncryptionChangedId) {
			vTable->call_encryption_changed = callEncryptionChange;
		}
326

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

332
		/*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
333
		newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
334
335
336
		if (newSubscriptionRequestId) {
			vTable->new_subscription_requested = new_subscription_requested;
		}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
337

338
		authInfoRequestedId = env->GetMethodID(listenerClass,"authInfoRequested","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
339
340
341
		if (authInfoRequestedId) {
			vTable->auth_info_requested = authInfoRequested;
		}
342
343

		/*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
344
		notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
345
346
347
		if (notifyPresenceReceivedId) {
			vTable->notify_presence_received = notify_presence_received;
		}
348
349

		/*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
350
		textReceivedId = env->GetMethodID(listenerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
351
352
353
		if (textReceivedId) {
			vTable->text_received = text_received;
		}
354

Simon Morlat's avatar
Simon Morlat committed
355
		messageReceivedId = env->GetMethodID(listenerClass,"messageReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneChatMessage;)V");
356
357
358
		if (messageReceivedId) {
			vTable->message_received = message_received;
		}
359

360
		isComposingReceivedId = env->GetMethodID(listenerClass,"isComposingReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;)V");
361
362
363
		if (isComposingReceivedId) {
			vTable->is_composing_received = is_composing_received;
		}
364

Sylvain Berfini's avatar
Sylvain Berfini committed
365
		dtmfReceivedId = env->GetMethodID(listenerClass,"dtmfReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;I)V");
366
367
368
		if (dtmfReceivedId) {
			vTable->dtmf_received = dtmf_received;
		}
369

370
371
372
373
		infoReceivedId = env->GetMethodID(listenerClass,"infoReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneInfoMessage;)V");
		if (infoReceivedId) {
			vTable->info_received = infoReceived;
		}
374

375
376
		subscriptionStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionState"));
		subscriptionStateFromIntId = env->GetStaticMethodID(subscriptionStateClass,"fromInt","(I)Lorg/linphone/core/SubscriptionState;");
377
		subscriptionStateId = env->GetMethodID(listenerClass,"subscriptionStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/SubscriptionState;)V");
378
379
380
		if (subscriptionStateId) {
			vTable->subscription_state_changed = subscriptionStateChanged;
		}
381

382
383
		publishStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/PublishState"));
		publishStateFromIntId = env->GetStaticMethodID(publishStateClass,"fromInt","(I)Lorg/linphone/core/PublishState;");
384
		publishStateId = env->GetMethodID(listenerClass,"publishStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Lorg/linphone/core/PublishState;)V");
385
386
387
		if (publishStateId) {
			vTable->publish_state_changed = publishStateChanged;
		}
388

389
390
391
392
		notifyRecvId = env->GetMethodID(listenerClass,"notifyReceived", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneEvent;Ljava/lang/String;Lorg/linphone/core/LinphoneContent;)V");
		if (notifyRecvId) {
			vTable->notify_received = notifyReceived;
		}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
393

394
395
		configuringStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RemoteProvisioningState"));
		configuringStateFromIntId = env->GetStaticMethodID(configuringStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;");
396
		configuringStateId = env->GetMethodID(listenerClass,"configuringStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$RemoteProvisioningState;Ljava/lang/String;)V");
397
398
399
		if (configuringStateId) {
			vTable->configuring_status = configuringStatus;
		}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
400

401
402
403
404
		fileTransferProgressIndicationId = env->GetMethodID(listenerClass, "fileTransferProgressIndication", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;I)V");
		if (fileTransferProgressIndicationId) {
			vTable->file_transfer_progress_indication = fileTransferProgressIndication;
		}
405

406
407
408
409
410
411
412
413
414
		fileTransferSendId = env->GetMethodID(listenerClass, "fileTransferSend", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;Ljava/nio/ByteBuffer;I)I");
		if (fileTransferSendId) {
			vTable->file_transfer_send = fileTransferSend;
		}

		fileTransferRecvId = env->GetMethodID(listenerClass, "fileTransferRecv", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;[BI)V");
		if (fileTransferRecvId) {
			vTable->file_transfer_recv = fileTransferRecv;
		}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
415

416
417
		logCollectionUploadStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$LogCollectionUploadState"));
		logCollectionUploadStateFromIntId = env->GetStaticMethodID(logCollectionUploadStateClass, "fromInt", "(I)Lorg/linphone/core/LinphoneCore$LogCollectionUploadState;");
Sylvain Berfini's avatar
Sylvain Berfini committed
418
		logCollectionUploadProgressId = env->GetMethodID(listenerClass, "uploadProgressIndication", "(Lorg/linphone/core/LinphoneCore;II)V");
419
420
421
422
423
424
425
		if (logCollectionUploadProgressId) {
			vTable->log_collection_upload_progress_indication = logCollectionUploadProgressIndication;
		}
		logCollectionUploadStateId = env->GetMethodID(listenerClass, "uploadStateChanged", "(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$LogCollectionUploadState;Ljava/lang/String;)V");
		if (logCollectionUploadStateId) {
			vTable->log_collection_upload_state_changed = logCollectionUploadStateChange;
		}
426
427
428

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

430
		proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
431
		proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(Lorg/linphone/core/LinphoneCoreImpl;J)V");
432
433
434

		callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
		callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
435
436
		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
437

438
		chatMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatMessageImpl"));
439
440
441
		if (chatMessageClass) {
			chatMessageCtrId = env->GetMethodID(chatMessageClass,"<init>", "(J)V");
		}
442

443
444
445
446
		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"));;
447
		friendCtrId = env->GetMethodID(friendClass,"<init>", "(J)V");
448

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

452
453
		callStatsClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallStatsImpl"));
		callStatsId = env->GetMethodID(callStatsClass, "<init>", "(JJ)V");
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
454

455
456
		infoMessageClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneInfoMessageImpl"));
		infoMessageCtor = env->GetMethodID(infoMessageClass,"<init>", "(J)V");
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
457

458
459
		linphoneEventClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneEventImpl"));
		linphoneEventCtrId = env->GetMethodID(linphoneEventClass,"<init>", "(J)V");
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
460

461
462
		subscriptionDirClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/SubscriptionDir"));
		subscriptionDirFromIntId = env->GetStaticMethodID(subscriptionDirClass,"fromInt","(I)Lorg/linphone/core/SubscriptionDir;");
jehan's avatar
jehan committed
463
464
465
466
467
468
469
	}

	~LinphoneCoreData() {
		JNIEnv *env = 0;
		jvm->AttachCurrentThread(&env,NULL);
		env->DeleteGlobalRef(core);
		env->DeleteGlobalRef(listener);
470
		env->DeleteGlobalRef(listenerClass);
jehan's avatar
jehan committed
471
		env->DeleteGlobalRef(globalStateClass);
472
		env->DeleteGlobalRef(configuringStateClass);
jehan's avatar
jehan committed
473
474
		env->DeleteGlobalRef(registrationStateClass);
		env->DeleteGlobalRef(callStateClass);
475
		env->DeleteGlobalRef(chatMessageStateClass);
jehan's avatar
jehan committed
476
477
		env->DeleteGlobalRef(proxyClass);
		env->DeleteGlobalRef(callClass);
478
		env->DeleteGlobalRef(chatMessageClass);
479
480
		env->DeleteGlobalRef(chatRoomClass);
		env->DeleteGlobalRef(friendClass);
481
		env->DeleteGlobalRef(infoMessageClass);
482
483
484
		env->DeleteGlobalRef(linphoneEventClass);
		env->DeleteGlobalRef(subscriptionStateClass);
		env->DeleteGlobalRef(subscriptionDirClass);
485
		env->DeleteGlobalRef(logCollectionUploadStateClass);
jehan's avatar
jehan committed
486
487
488
489
	}
	jobject core;
	jobject listener;

490
	jclass listenerClass;
jehan's avatar
jehan committed
491
	jmethodID displayStatusId;
492
493
494
	jmethodID newSubscriptionRequestId;
	jmethodID notifyPresenceReceivedId;
	jmethodID textReceivedId;
495
	jmethodID messageReceivedId;
496
	jmethodID isComposingReceivedId;
Sylvain Berfini's avatar
Sylvain Berfini committed
497
	jmethodID dtmfReceivedId;
498
	jmethodID callStatsUpdatedId;
499
	jmethodID transferStateId;
500
	jmethodID infoReceivedId;
501
	jmethodID subscriptionStateId;
502
	jmethodID authInfoRequestedId;
503
	jmethodID publishStateId;
504
	jmethodID notifyRecvId;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
505

506
507
508
	jclass configuringStateClass;
	jmethodID configuringStateId;
	jmethodID configuringStateFromIntId;
509
510
511
512
513
514
515
516
517
518
519
520
521

	jclass globalStateClass;
	jmethodID globalStateId;
	jmethodID globalStateFromIntId;

	jclass registrationStateClass;
	jmethodID registrationStateId;
	jmethodID registrationStateFromIntId;

	jclass callStateClass;
	jmethodID callStateId;
	jmethodID callStateFromIntId;

522
523
524
525
526
	jclass callStatsClass;
	jmethodID callStatsId;
	jmethodID callSetAudioStatsId;
	jmethodID callSetVideoStatsId;

527
528
529
	jclass chatMessageStateClass;
	jmethodID chatMessageStateFromIntId;

530
531
	jmethodID callEncryptionChangedId;

jehan's avatar
jehan committed
532
533
534
535
	jclass ecCalibratorStatusClass;
	jmethodID ecCalibrationStatusId;
	jmethodID ecCalibratorStatusFromIntId;

536
537
538
539
540
541
	jclass proxyClass;
	jmethodID proxyCtrId;

	jclass callClass;
	jmethodID callCtrId;

542
543
544
	jclass chatMessageClass;
	jmethodID chatMessageCtrId;

545
546
547
548
549
550
	jclass chatRoomClass;
	jmethodID chatRoomCtrId;

	jclass friendClass;
	jmethodID friendCtrId;

jehan's avatar
jehan committed
551
552
	jclass addressClass;
	jmethodID addressCtrId;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
553

554
555
	jclass infoMessageClass;
	jmethodID infoMessageCtor;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
556

557
558
	jclass linphoneEventClass;
	jmethodID linphoneEventCtrId;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
559

560
561
	jclass subscriptionStateClass;
	jmethodID subscriptionStateFromIntId;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
562

563
564
	jclass publishStateClass;
	jmethodID publishStateFromIntId;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
565

566
567
	jclass subscriptionDirClass;
	jmethodID subscriptionDirFromIntId;
jehan's avatar
jehan committed
568

569
	jmethodID fileTransferProgressIndicationId;
570
571
	jmethodID fileTransferSendId;
	jmethodID fileTransferRecvId;
572

573
574
575
576
577
	jclass logCollectionUploadStateClass;
	jmethodID logCollectionUploadStateId;
	jmethodID logCollectionUploadStateFromIntId;
	jmethodID logCollectionUploadProgressId;

jehan's avatar
jehan committed
578
	LinphoneCoreVTable vTable;
579

jehan's avatar
jehan committed
580
581
582
583
	static void displayStatusCb(LinphoneCore *lc, const char *message) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
584
			ms_error("cannot attach VM");
jehan's avatar
jehan committed
585
586
			return;
		}
587
588
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
589
590
591
592
593
		jstring msg = message ? env->NewStringUTF(message) : NULL;
		env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,msg);
		if (msg) {
			env->DeleteLocalRef(msg);
		}
jehan's avatar
jehan committed
594
	}
595
	static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) {
596
597
598
599
600
601
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM");
			return;
		}
602
603
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
604
605
606
		jstring r = realm ? env->NewStringUTF(realm) : NULL;
		jstring u = username ? env->NewStringUTF(username) : NULL;
		jstring d = domain ? env->NewStringUTF(domain) : NULL;
607
608
609
		env->CallVoidMethod(lcData->listener,
							lcData->authInfoRequestedId,
							lcData->core,
610
611
612
613
614
615
616
617
618
619
620
621
							r,
							u,
							d);
		if (r) {
			env->DeleteLocalRef(r);
		}
		if (u) {
			env->DeleteLocalRef(u);
		}
		if (d) {
			env->DeleteLocalRef(d);
		}
jehan's avatar
jehan committed
622
	}
623
624
625
626
	static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
627
			ms_error("cannot attach VM");
628
629
			return;
		}
630
631
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
632
		jstring msg = message ? env->NewStringUTF(message) : NULL;
633
634
635
		env->CallVoidMethod(lcData->listener
							,lcData->globalStateId
							,lcData->core
jehan's avatar
jehan committed
636
							,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
637
							msg);
638
639
640
641
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
642
643
644
		if (msg) {
			env->DeleteLocalRef(msg);
		}
645
	}
jehan's avatar
jehan committed
646
	static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
jehan's avatar
jehan committed
647
648
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
649
		jobject jproxy;
jehan's avatar
jehan committed
650
		if (result != 0) {
651
			ms_error("cannot attach VM");
jehan's avatar
jehan committed
652
653
			return;
		}
654
655
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
656
		jstring msg = message ? env->NewStringUTF(message) : NULL;
jehan's avatar
jehan committed
657
		env->CallVoidMethod(lcData->listener
658
							,lcData->registrationStateId
jehan's avatar
jehan committed
659
							,lcData->core
660
							,(jproxy=getProxy(env,proxy,lcData->core))
jehan's avatar
jehan committed
661
							,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
662
							msg);
663
664
665
666
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
667
668
669
		if (msg) {
			env->DeleteLocalRef(msg);
		}
jehan's avatar
jehan committed
670
	}
671

jehan's avatar
jehan committed
672
	static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
673
674
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
675
		jobject jcall;
676
		if (result != 0) {
677
			ms_error("cannot attach VM");
678
679
			return;
		}
680
681
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
682
		jstring msg = message ? env->NewStringUTF(message) : NULL;
683
684
685
		env->CallVoidMethod(lcData->listener
							,lcData->callStateId
							,lcData->core
686
							,(jcall=getCall(env,call))
jehan's avatar
jehan committed
687
							,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
688
							msg);
689
690
691
692
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
693
		if (state==LinphoneCallReleased) {
694
695
696
			linphone_call_set_user_pointer(call,NULL);
			env->DeleteGlobalRef(jcall);
		}
697
698
699
		if (msg) {
			env->DeleteLocalRef(msg);
		}
700
	}
701
702
703
704
	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) {
705
			ms_error("cannot attach VM");
706
707
			return;
		}
708
709
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
710
711
712
		env->CallVoidMethod(lcData->listener
							,lcData->callEncryptionChangedId
							,lcData->core
713
							,getCall(env,call)
714
715
							,encrypted
							,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
716
717
718
719
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
720
	}
721
	static void notify_presence_received(LinphoneCore *lc,  LinphoneFriend *my_friend) {
722
723
724
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
725
			ms_error("cannot attach VM");
726
727
			return;
		}
728
729
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
730
731
732
733
		env->CallVoidMethod(lcData->listener
							,lcData->notifyPresenceReceivedId
							,lcData->core
							,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
734
735
736
737
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
738
	}
739
	static void new_subscription_requested(LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
740
741
742
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
743
			ms_error("cannot attach VM");
744
745
			return;
		}
746
747
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
748
749
750
751
752
		env->CallVoidMethod(lcData->listener
							,lcData->newSubscriptionRequestId
							,lcData->core
							,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
							,url ? env->NewStringUTF(url) : NULL);
753
754
755
756
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
757
	}
Sylvain Berfini's avatar
Sylvain Berfini committed
758
759
760
761
	static void dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
762
			ms_error("cannot attach VM");
Sylvain Berfini's avatar
Sylvain Berfini committed
763
764
			return;
		}
765
766
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
Sylvain Berfini's avatar
Sylvain Berfini committed
767
768
769
		env->CallVoidMethod(lcData->listener
							,lcData->dtmfReceivedId
							,lcData->core
770
							,getCall(env,call)
Sylvain Berfini's avatar
Sylvain Berfini committed
771
							,dtmf);
772
773
774
775
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
Sylvain Berfini's avatar
Sylvain Berfini committed
776
	}
777
778
779
780
	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) {
781
			ms_error("cannot attach VM");
782
783
			return;
		}
784
785
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
786
787
788
789
		env->CallVoidMethod(lcData->listener
							,lcData->textReceivedId
							,lcData->core
							,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
jehan's avatar
jehan committed
790
							,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
791
							,message ? env->NewStringUTF(message) : NULL);
792
793
794
795
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
796
	}
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
797
	static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
798
799
800
801
802
803
		JNIEnv *env = 0;
		jobject jmsg;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM");
			return;
804
		}
805
806
807
808
809
810
811
812
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
		/*note: we call linphone_chat_message_ref() because the application does not acquire the object when invoked from a callback*/
		env->CallVoidMethod(lcData->listener
							,lcData->messageReceivedId
							,lcData->core
							,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
							,(jmsg = getChatMessage(env, msg)));
813
814
815
816
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
817
	}
818
819
820
821
822
823
824
	static void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
			ms_error("cannot attach VM");
			return;
		}
825
826
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
827
828
829
830
		env->CallVoidMethod(lcData->listener
							,lcData->isComposingReceivedId
							,lcData->core
							,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room));
831
832
833
834
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
835
	}
jehan's avatar
jehan committed
836
837
838
839
	static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
840
			ms_error("cannot attach VM");
jehan's avatar
jehan committed
841
842
			return;
		}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
843

844
845
846
847
848
849
850
851
852
853
		LinphoneCoreVTable *table = (LinphoneCoreVTable*) data;
		if (table) {
			LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_v_table_get_user_data(table);
			if (lcData->ecCalibrationStatusId) {
				jobject state = env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass, lcData->ecCalibratorStatusFromIntId, (jint)status);
				env->CallVoidMethod(lcData->listener
								,lcData->ecCalibrationStatusId
								,lcData->core
								,state
								,delay_ms
854
								,NULL);
855
856
857
858
			}
			if (status != LinphoneEcCalibratorInProgress) {
				linphone_core_v_table_destroy(table);
			}
jehan's avatar
jehan committed
859
860
861
		}

	}
862
863
864
865
866
867
	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) {
868
			ms_error("cannot attach VM");
869
870
			return;
		}
871
872
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
873
		statsobj = env->NewObject(lcData->callStatsClass, lcData->callStatsId, (jlong)call, (jlong)stats);
874
		callobj = getCall(env, call);
875
876
877
878
879
		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);
880
881
882
883
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
884
	}
885
886
887
888
889
	static void transferStateChanged(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState remote_call_state){
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		jobject jcall;
		if (result != 0) {
890
			ms_error("cannot attach VM");
891
892
			return;
		}
893
894
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
895
896
897
		env->CallVoidMethod(lcData->listener
							,lcData->transferStateId
							,lcData->core
898
							,(jcall=getCall(env,call))
899
900
							,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)remote_call_state)
							);
901
902
903
904
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
905
	}
906
	static void infoReceived(LinphoneCore *lc, LinphoneCall*call, const LinphoneInfoMessage *info){
907
908
909
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		if (result != 0) {
910
			ms_error("cannot attach VM");
911
912
913
			return;
		}
		LinphoneInfoMessage *copy_info=linphone_info_message_copy(info);
914
915
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
916
917
918
		env->CallVoidMethod(lcData->listener
							,lcData->infoReceivedId
							,lcData->core
919
							,getCall(env,call)
920
921
							,env->NewObject(lcData->infoMessageClass,lcData->infoMessageCtor,(jlong)copy_info)
							);
922
923
924
925
		if (env->ExceptionCheck()) {
			ms_error("Listener %p raised an exception",lcData->listener);
			env->ExceptionClear();
		}
926
	}
927
928
929
930
931
932
933
934
935
	static void subscriptionStateChanged(LinphoneCore *lc, LinphoneEvent *ev, LinphoneSubscriptionState state){
		JNIEnv *env = 0;
		jint result = jvm->AttachCurrentThread(&env,NULL);
		jobject jevent;
		jobject jstate;
		if (result != 0) {
			ms_error("cannot attach VM");
			return;
		}
936
937
938
		LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
		LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);