LinphoneCore.cpp 51.6 KB
Newer Older
1
#include "LinphoneCore.h"
2 3 4
#include "LinphoneAddress.h"
#include "LinphoneAuthInfo.h"
#include "LinphoneCall.h"
5
#include "LinphoneCallLog.h"
6 7
#include "LinphoneCallParams.h"
#include "LinphoneProxyConfig.h"
8
#include "LinphoneCoreListener.h"
9
#include "LinphoneChatRoom.h"
10 11
#include "LpConfig.h"
#include "PayloadType.h"
12
#include "CallController.h"
Ghislain MARY's avatar
Ghislain MARY committed
13
#include "Tunnel.h"
14
#include "Server.h"
15
#include "Enums.h"
16 17
#include "ApiLock.h"
#include <collection.h>
18

19
using namespace Platform;
20
using namespace Platform::Collections;
21
using namespace Windows::Foundation;
22
using namespace Windows::Foundation::Collections;
23
using namespace Windows::Phone::Media::Devices;
24
using namespace Windows::Phone::Networking::Voip;
25
using namespace Windows::System::Threading;
26

27 28 29 30
Linphone::Core::Transports::Transports() :
	udp(5060),
	tcp(0),
	tls(0)
31
{
32 33
}

34 35 36 37 38 39 40
Linphone::Core::Transports::Transports(int udp_port, int tcp_port, int tls_port) :
	udp(udp_port),
	tcp(tcp_port),
	tls(tls_port)
{
}

41
Linphone::Core::Transports::Transports(Linphone::Core::Transports^ t) :
42 43 44 45 46 47
	udp(t->UDP),
	tcp(t->TCP),
	tls(t->TLS)
{
}

48
int Linphone::Core::Transports::UDP::get()
49 50 51 52
{
	return udp;
}

53 54 55 56 57 58 59
void Linphone::Core::Transports::UDP::set(int value)
{
	this->udp = value;
	this->tcp = 0;
	this->tls = 0;
}

60
int Linphone::Core::Transports::TCP::get()
61 62 63 64
{
	return tcp;
}

65 66 67 68 69 70 71
void Linphone::Core::Transports::TCP::set(int value)
{
	this->udp = 0;
	this->tcp = value;
	this->tls = 0;
}

72
int Linphone::Core::Transports::TLS::get()
73 74 75 76
{
	return tls;
}

77 78 79 80 81 82 83
void Linphone::Core::Transports::TLS::set(int value)
{
	this->udp = 0;
	this->tcp = 0;
	this->tls = value;
}

84
Platform::String^ Linphone::Core::Transports::ToString()
85 86 87 88
{
	return "udp[" + udp + "] tcp[" + tcp + "] tls[" + tls + "]";
}

89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

Linphone::Core::VideoPolicy::VideoPolicy() :
	automaticallyInitiate(true), automaticallyAccept(true)
{
}

Linphone::Core::VideoPolicy::VideoPolicy(bool automaticallyInitiate, bool automaticallyAccept) :
	automaticallyInitiate(automaticallyInitiate), automaticallyAccept(automaticallyAccept)
{
}

bool Linphone::Core::VideoPolicy::AutomaticallyInitiate::get()
{
	return automaticallyInitiate;
}

void Linphone::Core::VideoPolicy::AutomaticallyInitiate::set(bool value)
{
	automaticallyInitiate = value;
}

bool Linphone::Core::VideoPolicy::AutomaticallyAccept::get()
{
	return automaticallyAccept;
}

void Linphone::Core::VideoPolicy::AutomaticallyAccept::set(bool value)
{
	automaticallyAccept = value;
}



Linphone::Core::VideoSize::VideoSize(int width, int height) :
	width(width), height(height), name("")
{
}

Linphone::Core::VideoSize::VideoSize(int width, int height, Platform::String^ name) :
	width(width), height(height), name(name)
{
}

int Linphone::Core::VideoSize::Width::get()
{
	return width;
}

void Linphone::Core::VideoSize::Width::set(int value)
{
	width = value;
}

int Linphone::Core::VideoSize::Height::get()
{
	return height;
}

void Linphone::Core::VideoSize::Height::set(int value)
{
	height = value;
}

Platform::String^ Linphone::Core::VideoSize::Name::get()
{
	return name;
}

void Linphone::Core::VideoSize::Name::set(Platform::String^ value)
{
	name = value;
}



165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
void Linphone::Core::LinphoneCore::SetLogLevel(OutputTraceLevel logLevel)
{
	int coreLogLevel = 0;
	if (logLevel == OutputTraceLevel::Error) {
		coreLogLevel = ORTP_ERROR | ORTP_FATAL;
	}
	else if (logLevel == OutputTraceLevel::Warning) {
		coreLogLevel = ORTP_WARNING | ORTP_ERROR | ORTP_FATAL;
	}
	else if (logLevel == OutputTraceLevel::Message) {
		coreLogLevel = ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL;
	}
	else if (logLevel == OutputTraceLevel::Debug) {
		coreLogLevel = ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL;
	}
	Utils::LinphoneCoreSetLogLevel(coreLogLevel);
}

183
void Linphone::Core::LinphoneCore::ClearProxyConfigs()
184
{
185
	gApiLock.Lock();
186
	linphone_core_clear_proxy_config(this->lc);
187
	gApiLock.Unlock();
188 189
}

190
void Linphone::Core::LinphoneCore::AddProxyConfig(Linphone::Core::LinphoneProxyConfig^ proxyCfg)
191
{
192
	gApiLock.Lock();
193
	linphone_core_add_proxy_config(this->lc, proxyCfg->proxy_config);
194
	gApiLock.Unlock();
195 196
}

197
void Linphone::Core::LinphoneCore::SetDefaultProxyConfig(Linphone::Core::LinphoneProxyConfig^ proxyCfg)
198
{
199
	gApiLock.Lock();
Sylvain Berfini's avatar
Sylvain Berfini committed
200
	linphone_core_set_default_proxy(this->lc, proxyCfg->proxy_config);
201
	gApiLock.Unlock();
202 203
}

204
Linphone::Core::LinphoneProxyConfig^ Linphone::Core::LinphoneCore::GetDefaultProxyConfig()
205
{
206 207
	gApiLock.Lock();
	LinphoneProxyConfig^ defaultProxy = nullptr;
Sylvain Berfini's avatar
Sylvain Berfini committed
208 209
	::LinphoneProxyConfig *proxy=NULL;
	linphone_core_get_default_proxy(this->lc,&proxy);
210
	if (proxy != nullptr) {
211
		defaultProxy = ref new Linphone::Core::LinphoneProxyConfig(proxy);
212
	}
213
	gApiLock.Unlock();
214
	return defaultProxy;
215 216
}

217 218
Linphone::Core::LinphoneProxyConfig^ Linphone::Core::LinphoneCore::CreateEmptyProxyConfig()
{
219
	gApiLock.Lock();
220
	Linphone::Core::LinphoneProxyConfig^ proxyConfig = ref new Linphone::Core::LinphoneProxyConfig();
221
	gApiLock.Unlock();
222 223 224
	return proxyConfig;
}

225 226 227 228 229 230 231 232 233 234
static void AddProxyConfigToVector(void *vProxyConfig, void *vector)
{
	::LinphoneProxyConfig *pc = (LinphoneProxyConfig *)vProxyConfig;
	Linphone::Core::RefToPtrProxy<IVector<Object^>^> *list = reinterpret_cast< Linphone::Core::RefToPtrProxy<IVector<Object^>^> *>(vector);
	IVector<Object^>^ proxyconfigs = (list) ? list->Ref() : nullptr;

	Linphone::Core::LinphoneProxyConfig^ proxyConfig = (Linphone::Core::LinphoneProxyConfig^)Linphone::Core::Utils::CreateLinphoneProxyConfig(pc);
	proxyconfigs->Append(proxyConfig);
}

235
IVector<Object^>^ Linphone::Core::LinphoneCore::GetProxyConfigList() 
236
{
237
	gApiLock.Lock();
238 239 240 241
	IVector<Object^>^ proxyconfigs = ref new Vector<Object^>();
	const MSList *configList = linphone_core_get_proxy_config_list(this->lc);
	RefToPtrProxy<IVector<Object^>^> *proxyConfigPtr = new RefToPtrProxy<IVector<Object^>^>(proxyconfigs);
	ms_list_for_each2(configList, AddProxyConfigToVector, proxyConfigPtr);
242
	gApiLock.Unlock();
243
	return proxyconfigs;
244 245
}

246
void Linphone::Core::LinphoneCore::ClearAuthInfos() 
247
{
248
	gApiLock.Lock();
249
	linphone_core_clear_all_auth_info(this->lc);
250
	gApiLock.Unlock();
251 252
}

253
void Linphone::Core::LinphoneCore::AddAuthInfo(Linphone::Core::LinphoneAuthInfo^ info) 
254
{
255
	gApiLock.Lock();
256
	linphone_core_add_auth_info(this->lc, info->auth_info);
257
	gApiLock.Unlock();
258
}
259

Sylvain Berfini's avatar
Sylvain Berfini committed
260
Linphone::Core::LinphoneAuthInfo^ Linphone::Core::LinphoneCore::CreateAuthInfo(Platform::String^ username, Platform::String^ userid, Platform::String^ password, Platform::String^ ha1, Platform::String^ realm, Platform::String^ domain)
261
{
262
	gApiLock.Lock();
Sylvain Berfini's avatar
Sylvain Berfini committed
263
	Linphone::Core::LinphoneAuthInfo^ authInfo = ref new Linphone::Core::LinphoneAuthInfo(username, userid, password, ha1, realm, domain);
264
	gApiLock.Unlock();
265
	return authInfo;
266 267
}

268 269 270 271 272 273 274 275 276 277 278 279
static void AddAuthInfoToVector(void *vAuthInfo, void *vector)
{
	::LinphoneAuthInfo *ai = (LinphoneAuthInfo *)vAuthInfo;
	Linphone::Core::RefToPtrProxy<IVector<Object^>^> *list = reinterpret_cast< Linphone::Core::RefToPtrProxy<IVector<Object^>^> *>(vector);
	IVector<Object^>^ authInfos = (list) ? list->Ref() : nullptr;

	Linphone::Core::LinphoneAuthInfo^ authInfo = (Linphone::Core::LinphoneAuthInfo^)Linphone::Core::Utils::CreateLinphoneAuthInfo(ai);
	authInfos->Append(authInfo);
}

IVector<Object^>^ Linphone::Core::LinphoneCore::GetAuthInfos()
{
280
	gApiLock.Lock();
281 282 283 284
	IVector<Object^>^ authInfos = ref new Vector<Object^>();
	const MSList *authlist = linphone_core_get_auth_info_list(this->lc);
	RefToPtrProxy<IVector<Object^>^> *authInfosPtr = new RefToPtrProxy<IVector<Object^>^>(authInfos);
	ms_list_for_each2(authlist, AddAuthInfoToVector, authInfosPtr);
285
	gApiLock.Unlock();
286 287 288
	return authInfos;
}

289
void Linphone::Core::LinphoneCore::Destroy() 
290
{
291
	gApiLock.Lock();
292
	IterateEnabled = false;
293
	gApiLock.Unlock();
294 295
}

296
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneCore::InterpretURL(Platform::String^ destination) 
297
{
298
	gApiLock.Lock();
299 300 301
	const char* url = Linphone::Core::Utils::pstoccs(destination);
	Linphone::Core::LinphoneAddress^ addr = (Linphone::Core::LinphoneAddress^) Linphone::Core::Utils::CreateLinphoneAddress(linphone_core_interpret_url(this->lc, url));
	delete(url);
302
	gApiLock.Unlock();
303
	return addr;
304 305
}

306
Linphone::Core::LinphoneCall^ Linphone::Core::LinphoneCore::Invite(Platform::String^ destination) 
307
{
308 309
	gApiLock.Lock();
	Linphone::Core::LinphoneCall^ lCall = nullptr;
310 311 312
	const char *cc = Linphone::Core::Utils::pstoccs(destination);
	::LinphoneCall *call = linphone_core_invite(this->lc, cc);
	delete(cc);
313
	if (call != NULL) {
314
		Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(call));
315
		lCall = (proxy) ? proxy->Ref() : nullptr;
316
		if (lCall == nullptr)
317 318
			lCall = (Linphone::Core::LinphoneCall^)Linphone::Core::Utils::CreateLinphoneCall(call);
	}
319 320
	gApiLock.Unlock();
	return lCall;
321 322
}

Ghislain MARY's avatar
Ghislain MARY committed
323
Linphone::Core::LinphoneCall^ Linphone::Core::LinphoneCore::InviteAddress(Linphone::Core::LinphoneAddress^ destination) 
324
{
325
	gApiLock.Lock();
326 327 328 329 330 331 332 333
	Linphone::Core::LinphoneCall^ lCall = nullptr;
	::LinphoneCall *call = linphone_core_invite_address(this->lc, destination->address);
	if (call != NULL) {
		Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(call));
		lCall = (proxy) ? proxy->Ref() : nullptr;
		if (lCall == nullptr)
			lCall = (Linphone::Core::LinphoneCall^) Linphone::Core::Utils::CreateLinphoneCall(call);
	}
334 335
	gApiLock.Unlock();
	return lCall;
336 337
}

338
Linphone::Core::LinphoneCall^ Linphone::Core::LinphoneCore::InviteAddressWithParams(Linphone::Core::LinphoneAddress^ destination, LinphoneCallParams^ params) 
339
{
340
	gApiLock.Lock();
341 342 343 344 345 346 347 348
	Linphone::Core::LinphoneCall^ lCall = nullptr;
	::LinphoneCall *call = linphone_core_invite_address_with_params(this->lc, destination->address, params->params);
	if (call != NULL) {
		Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(call));
		lCall = (proxy) ? proxy->Ref() : nullptr;
		if (lCall == nullptr)
			lCall = (Linphone::Core::LinphoneCall^) Linphone::Core::Utils::CreateLinphoneCall(call);
	}
349 350
	gApiLock.Unlock();
	return lCall;
351 352
}

353
void Linphone::Core::LinphoneCore::TerminateCall(Linphone::Core::LinphoneCall^ call) 
354
{
355
	gApiLock.Lock();
356
	linphone_core_terminate_call(this->lc, call->call);
357
	gApiLock.Unlock();
358 359
}

360 361 362 363 364 365 366
void Linphone::Core::LinphoneCore::DeclineCall(Linphone::Core::LinphoneCall^ call, DeclineReason reason)
{
	gApiLock.Lock();
	linphone_core_decline_call(this->lc, call->call, (LinphoneReason)reason);
	gApiLock.Unlock();
}

367
Linphone::Core::LinphoneCall^ Linphone::Core::LinphoneCore::GetCurrentCall() 
368
{
369 370
	gApiLock.Lock();
	Linphone::Core::LinphoneCall^ lCall = nullptr;
371
	::LinphoneCall *call = linphone_core_get_current_call(this->lc);
372 373 374 375 376
	if (call != nullptr) {
		Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(call));
		lCall = (proxy) ? proxy->Ref() : nullptr;
	}
	gApiLock.Unlock();
377
	return lCall;
378 379
}

380
Platform::Boolean Linphone::Core::LinphoneCore::IsInCall() 
381
{
382
	gApiLock.Lock();
383
	Platform::Boolean inCall = (linphone_core_in_call(this->lc) == TRUE);
384 385
	gApiLock.Unlock();
	return inCall;
386 387
}

388
Platform::Boolean Linphone::Core::LinphoneCore::IsIncomingInvitePending() 
389
{
390
	gApiLock.Lock();
391
	Platform::Boolean invitePending = (linphone_core_inc_invite_pending(this->lc) == TRUE);
392 393
	gApiLock.Unlock();
	return invitePending;
394 395
}

396
void Linphone::Core::LinphoneCore::AcceptCall(Linphone::Core::LinphoneCall^ call) 
397
{
398
	gApiLock.Lock();
399
	linphone_core_accept_call(this->lc, call->call);
400
	gApiLock.Unlock();
401 402
}

403
void Linphone::Core::LinphoneCore::AcceptCallWithParams(Linphone::Core::LinphoneCall^ call, Linphone::Core::LinphoneCallParams^ params) 
404
{
405
	gApiLock.Lock();
406
	linphone_core_accept_call_with_params(this->lc, call->call, params->params);
407
	gApiLock.Unlock();
408 409
}

410
void Linphone::Core::LinphoneCore::AcceptCallUpdate(Linphone::Core::LinphoneCall^ call, Linphone::Core::LinphoneCallParams^ params) 
411
{
412
	gApiLock.Lock();
413
	linphone_core_accept_call_update(this->lc, call->call, params->params);
414
	gApiLock.Unlock();
415 416
}

417
void Linphone::Core::LinphoneCore::DeferCallUpdate(Linphone::Core::LinphoneCall^ call) 
418
{
419
	gApiLock.Lock();
420
	linphone_core_defer_call_update(this->lc, call->call);
421
	gApiLock.Unlock();
422 423
}

424
void Linphone::Core::LinphoneCore::UpdateCall(Linphone::Core::LinphoneCall^ call, Linphone::Core::LinphoneCallParams^ params) 
425
{
426
	gApiLock.Lock();
Ghislain MARY's avatar
Ghislain MARY committed
427 428 429 430 431
	if (params != nullptr) {
		linphone_core_update_call(this->lc, call->call, params->params);
	} else {
		linphone_core_update_call(this->lc, call->call, nullptr);
	}
432
	gApiLock.Unlock();
433 434
}

435
Linphone::Core::LinphoneCallParams^ Linphone::Core::LinphoneCore::CreateDefaultCallParameters() 
436
{
437 438 439 440
	gApiLock.Lock();
	Linphone::Core::LinphoneCallParams^ params = (Linphone::Core::LinphoneCallParams^) Linphone::Core::Utils::CreateLinphoneCallParams(linphone_core_create_default_call_parameters(this->lc));
	gApiLock.Unlock();
	return params;
441 442
}

Sylvain Berfini's avatar
Sylvain Berfini committed
443 444 445 446 447 448 449 450 451 452
void AddLogToVector(void* nLog, void* vector)
{
	::LinphoneCallLog *cl = (LinphoneCallLog*)nLog;
	Linphone::Core::RefToPtrProxy<IVector<Object^>^> *list = reinterpret_cast< Linphone::Core::RefToPtrProxy<IVector<Object^>^> *>(vector);
	IVector<Object^>^ logs = (list) ? list->Ref() : nullptr;

	Linphone::Core::LinphoneCallLog^ log = (Linphone::Core::LinphoneCallLog^)Linphone::Core::Utils::CreateLinphoneCallLog(cl);
	logs->Append(log);
}

453
IVector<Object^>^ Linphone::Core::LinphoneCore::GetCallLogs() 
454
{
455
	gApiLock.Lock();
456
	IVector<Object^>^ logs = ref new Vector<Object^>();
Sylvain Berfini's avatar
Sylvain Berfini committed
457 458 459
	const MSList* logslist = linphone_core_get_call_logs(this->lc);
	RefToPtrProxy<IVector<Object^>^> *logsptr = new RefToPtrProxy<IVector<Object^>^>(logs);
	ms_list_for_each2(logslist, AddLogToVector, logsptr);
460
	gApiLock.Unlock();
461
	return logs;
462 463
}

464
void Linphone::Core::LinphoneCore::ClearCallLogs() 
465
{
466
	gApiLock.Lock();
467
	linphone_core_clear_call_logs(this->lc);
468
	gApiLock.Unlock();
469 470
}

471
void Linphone::Core::LinphoneCore::RemoveCallLog(Linphone::Core::LinphoneCallLog^ log) 
472
{
473
	gApiLock.Lock();
474
	linphone_core_remove_call_log(this->lc, log->callLog);
475
	gApiLock.Unlock();
476 477
}

478
void Linphone::Core::LinphoneCore::SetNetworkReachable(Platform::Boolean isReachable) 
479
{
480
	gApiLock.Lock();
Sylvain Berfini's avatar
Sylvain Berfini committed
481
	linphone_core_set_network_reachable(this->lc, isReachable);
482
	gApiLock.Unlock();
483 484
}

485
Platform::Boolean Linphone::Core::LinphoneCore::IsNetworkReachable() 
486
{
487
	gApiLock.Lock();
488
	Platform::Boolean networkReachable = (linphone_core_is_network_reachable(this->lc) == TRUE);
489 490
	gApiLock.Unlock();
	return networkReachable;
491 492
}

493
void Linphone::Core::LinphoneCore::SetMicrophoneGain(float gain) 
494
{
495
	gApiLock.Lock();
496
	linphone_core_set_mic_gain_db(this->lc, gain);
497
	gApiLock.Unlock();
498
}
499

500 501
void Linphone::Core::LinphoneCore::SetPlaybackGain(float gain) 
{
502
	gApiLock.Lock();
503
	linphone_core_set_playback_gain_db(this->lc, gain);
504
	gApiLock.Unlock();
505 506
}

507
float Linphone::Core::LinphoneCore::GetPlaybackGain() 
508
{
509 510 511 512
	gApiLock.Lock();
	float gain = linphone_core_get_playback_gain_db(this->lc);
	gApiLock.Unlock();
	return gain;
513 514
}

515
void Linphone::Core::LinphoneCore::SetPlayLevel(int level) 
516
{
517
	gApiLock.Lock();
518
	linphone_core_set_play_level(this->lc, level);
519
	gApiLock.Unlock();
520 521
}

522
int Linphone::Core::LinphoneCore::GetPlayLevel() 
523
{
524 525 526 527
	gApiLock.Lock();
	int level = linphone_core_get_play_level(this->lc);
	gApiLock.Unlock();
	return level;
528 529
}

530
void Linphone::Core::LinphoneCore::MuteMic(Platform::Boolean isMuted) 
531
{
532
	gApiLock.Lock();
Sylvain Berfini's avatar
Sylvain Berfini committed
533
	linphone_core_mute_mic(this->lc, isMuted);
534
	gApiLock.Unlock();
535 536
}

537
Platform::Boolean Linphone::Core::LinphoneCore::IsMicMuted() 
538
{
539
	gApiLock.Lock();
540
	Platform::Boolean muted = (linphone_core_is_mic_muted(this->lc) == TRUE);
541 542
	gApiLock.Unlock();
	return muted;
543 544
}

545
void Linphone::Core::LinphoneCore::SendDTMF(char16 number) 
546
{
547
	gApiLock.Lock();
548 549 550 551
	char conv[4];
	if (wctomb(conv, number) == 1) {
		linphone_core_send_dtmf(this->lc, conv[0]);
	}
552
	gApiLock.Unlock();
553 554
}

555
void Linphone::Core::LinphoneCore::PlayDTMF(char16 number, int duration) 
556
{
557
	gApiLock.Lock();
558 559 560 561
	char conv[4];
	if (wctomb(conv, number) == 1) {
		linphone_core_play_dtmf(this->lc, conv[0], duration);
	}
562
	gApiLock.Unlock();
563 564
}

565
void Linphone::Core::LinphoneCore::StopDTMF() 
566
{
567
	gApiLock.Lock();
568
	linphone_core_stop_dtmf(this->lc);
569
	gApiLock.Unlock();
570 571
}

572
Linphone::Core::PayloadType^ Linphone::Core::LinphoneCore::FindPayloadType(Platform::String^ mime, int clockRate, int channels) 
573
{
574
	gApiLock.Lock();
575 576 577
	const char* type = Linphone::Core::Utils::pstoccs(mime);
	::PayloadType* pt = linphone_core_find_payload_type(this->lc, type, clockRate, channels);
	delete type;
578 579 580
	Linphone::Core::PayloadType^ payloadType = ref new Linphone::Core::PayloadType(pt);
	gApiLock.Unlock();
	return payloadType;
581 582
}

583
Linphone::Core::PayloadType^ Linphone::Core::LinphoneCore::FindPayloadType(Platform::String^ mime, int clockRate) 
584
{
585
	gApiLock.Lock();
586
	const char* type = Linphone::Core::Utils::pstoccs(mime);
587
	::PayloadType* pt = linphone_core_find_payload_type(this->lc, type, clockRate, LINPHONE_FIND_PAYLOAD_IGNORE_CHANNELS);
588
	delete type;
589 590 591
	Linphone::Core::PayloadType^ payloadType = ref new Linphone::Core::PayloadType(pt);
	gApiLock.Unlock();
	return payloadType;
592 593
}

594 595
bool Linphone::Core::LinphoneCore::PayloadTypeEnabled(PayloadType^ pt)
{
596
	gApiLock.Lock();
597
	::PayloadType *payload = pt->payload;
598
	bool enabled = (linphone_core_payload_type_enabled(this->lc, payload) == TRUE);
599 600
	gApiLock.Unlock();
	return enabled;
601 602
}

603
void Linphone::Core::LinphoneCore::EnablePayloadType(PayloadType^ pt, Platform::Boolean enable) 
604
{
605
	gApiLock.Lock();
606
	::PayloadType *payload = pt->payload;
607
	linphone_core_enable_payload_type(this->lc, payload, enable);
608
	gApiLock.Unlock();
609 610
}

611
static void AddCodecToVector(void *vCodec, void *vector)
612
{
613 614 615 616 617 618 619 620 621 622
	::PayloadType *pt = (PayloadType *)vCodec;
	Linphone::Core::RefToPtrProxy<IVector<Object^>^> *list = reinterpret_cast< Linphone::Core::RefToPtrProxy<IVector<Object^>^> *>(vector);
	IVector<Object^>^ codecs = (list) ? list->Ref() : nullptr;

	Linphone::Core::PayloadType^ codec = (Linphone::Core::PayloadType^)Linphone::Core::Utils::CreatePayloadType(pt);
	codecs->Append(codec);
}

IVector<Object^>^ Linphone::Core::LinphoneCore::GetAudioCodecs()
{
623
	gApiLock.Lock();
624 625 626 627
	IVector<Object^>^ codecs = ref new Vector<Object^>();
	const MSList *codecslist = linphone_core_get_audio_codecs(this->lc);
	RefToPtrProxy<IVector<Object^>^> *codecsPtr = new RefToPtrProxy<IVector<Object^>^>(codecs);
	ms_list_for_each2(codecslist, AddCodecToVector, codecsPtr);
628
	gApiLock.Unlock();
629
	return codecs;
630 631
}

632
void Linphone::Core::LinphoneCore::EnableEchoCancellation(Platform::Boolean enable) 
633
{
634
	gApiLock.Lock();
635
	linphone_core_enable_echo_cancellation(this->lc, enable);
636
	gApiLock.Unlock();
637 638
}

639
Platform::Boolean Linphone::Core::LinphoneCore::IsEchoCancellationEnabled() 
640
{
641
	gApiLock.Lock();
642
	Platform::Boolean enabled = (linphone_core_echo_cancellation_enabled(this->lc) == TRUE);
643 644
	gApiLock.Unlock();
	return enabled;
645 646
}

647
Platform::Boolean Linphone::Core::LinphoneCore::IsEchoLimiterEnabled() 
648
{
649
	gApiLock.Lock();
650
	Platform::Boolean enabled = (linphone_core_echo_limiter_enabled(this->lc) == TRUE);
651 652
	gApiLock.Unlock();
	return enabled;
653 654
}

655 656 657 658 659 660 661 662 663 664
static void EchoCalibrationCallback(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data)
{
	Linphone::Core::Utils::EchoCalibrationCallback(lc, status, delay_ms, data);
}

static void EchoCalibrationAudioInit(void *data)
{
	Linphone::Core::EchoCalibrationData *ecData = static_cast<Linphone::Core::EchoCalibrationData *>(data);
	if (ecData != nullptr) {
		ecData->endpoint = AudioRoutingManager::GetDefault()->GetAudioEndpoint();
665 666 667 668 669 670 671 672
		// Need to create a dummy VoipPhoneCall to be able to capture audio!
		VoipCallCoordinator::GetDefault()->RequestNewOutgoingCall(
			"ECCalibrator",
			"ECCalibrator",
			"ECCalibrator",
			VoipCallMedia::Audio,
			&ecData->call);
		ecData->call->NotifyCallActive();
673 674 675 676 677 678 679 680
	}
	AudioRoutingManager::GetDefault()->SetAudioEndpoint(AudioRoutingEndpoint::Speakerphone);
}

static void EchoCalibrationAudioUninit(void *data)
{
	Linphone::Core::EchoCalibrationData *ecData = static_cast<Linphone::Core::EchoCalibrationData *>(data);
	if (ecData != nullptr) {
681
		ecData->call->NotifyCallEnded();
682
		AudioRoutingManager::GetDefault()->SetAudioEndpoint(AudioRoutingEndpoint::Default);
683 684 685 686
	}
}

void Linphone::Core::LinphoneCore::StartEchoCalibration() 
687
{
688
	gApiLock.Lock();
689 690
	Linphone::Core::EchoCalibrationData *data = new Linphone::Core::EchoCalibrationData();
	linphone_core_start_echo_calibration(this->lc, EchoCalibrationCallback, EchoCalibrationAudioInit, EchoCalibrationAudioUninit, data);
691
	gApiLock.Unlock();
692 693
}

694
void Linphone::Core::LinphoneCore::EnableEchoLimiter(Platform::Boolean enable) 
695
{
696
	gApiLock.Lock();
697
	linphone_core_enable_echo_limiter(this->lc, enable);
698
	gApiLock.Unlock();
699 700
}

701
void Linphone::Core::LinphoneCore::SetSignalingTransportsPorts(Transports^ t) 
702
{
703
	gApiLock.Lock();
704 705 706 707 708 709
	::LCSipTransports transports;
	memset(&transports, 0, sizeof(LCSipTransports));
	transports.udp_port = t->UDP;
	transports.tcp_port = t->TCP;
	transports.tls_port = t->TLS;
	linphone_core_set_sip_transports(this->lc, &transports);
710
	gApiLock.Unlock();
711 712
}

713
Linphone::Core::Transports^ Linphone::Core::LinphoneCore::GetSignalingTransportsPorts()
714
{
715
	gApiLock.Lock();
716 717
	::LCSipTransports transports;
	linphone_core_get_sip_transports(this->lc, &transports);
718 719 720
	Linphone::Core::Transports^ t = ref new Linphone::Core::Transports(transports.udp_port, transports.tcp_port, transports.tls_port);
	gApiLock.Unlock();
	return t;
721 722
}

723
void Linphone::Core::LinphoneCore::EnableIPv6(Platform::Boolean enable) 
724
{
725
	gApiLock.Lock();
726
	linphone_core_enable_ipv6(this->lc, enable);
727
	gApiLock.Unlock();
728 729
}

730
void Linphone::Core::LinphoneCore::SetPresenceInfo(int minuteAway, Platform::String^ alternativeContact, OnlineStatus status) 
731
{
732
	gApiLock.Lock();
733 734 735
	const char* ac = Linphone::Core::Utils::pstoccs(alternativeContact);
	linphone_core_set_presence_info(this->lc, minuteAway, ac, (LinphoneOnlineStatus) status);
	delete(ac);
736
	gApiLock.Unlock();
737 738
}

739
void Linphone::Core::LinphoneCore::SetStunServer(Platform::String^ stun) 
740
{
741
	gApiLock.Lock();
742 743 744
	const char* stunserver = Linphone::Core::Utils::pstoccs(stun);
	linphone_core_set_stun_server(this->lc, stunserver);
	delete(stunserver);
745
	gApiLock.Unlock();
746 747
}

748
Platform::String^ Linphone::Core::LinphoneCore::GetStunServer() 
749
{
750 751 752 753
	gApiLock.Lock();
	Platform::String^ server = Linphone::Core::Utils::cctops(linphone_core_get_stun_server(this->lc));
	gApiLock.Unlock();
	return server;
754 755
}

756
void Linphone::Core::LinphoneCore::SetFirewallPolicy(FirewallPolicy policy) 
757
{
758
	gApiLock.Lock();
759
	linphone_core_set_firewall_policy(this->lc, (LinphoneFirewallPolicy) policy);
760
	gApiLock.Unlock();
761 762
}

763
Linphone::Core::FirewallPolicy Linphone::Core::LinphoneCore::GetFirewallPolicy() 
764
{
765 766 767 768
	gApiLock.Lock();
	Linphone::Core::FirewallPolicy policy = (Linphone::Core::FirewallPolicy) linphone_core_get_firewall_policy(this->lc);
	gApiLock.Unlock();
	return policy;
769 770
}

771
void Linphone::Core::LinphoneCore::SetRootCA(Platform::String^ path) 
772
{
773
	gApiLock.Lock();
Ghislain MARY's avatar
Ghislain MARY committed
774 775 776
	const char *ccPath = Utils::pstoccs(path);
	linphone_core_set_root_ca(this->lc, ccPath);
	delete ccPath;
777
	gApiLock.Unlock();
778 779
}

780
void Linphone::Core::LinphoneCore::SetUploadBandwidth(int bw) 
781
{
782
	gApiLock.Lock();
783
	linphone_core_set_upload_bandwidth(this->lc, bw);
784
	gApiLock.Unlock();
785 786
}

787
void Linphone::Core::LinphoneCore::SetDownloadBandwidth(int bw) 
788
{
789
	gApiLock.Lock();
790
	linphone_core_set_download_bandwidth(this->lc, bw);
791
	gApiLock.Unlock();
792 793
}

794
void Linphone::Core::LinphoneCore::SetDownloadPTime(int ptime) 
795
{
796
	gApiLock.Lock();
797
	linphone_core_set_download_ptime(this->lc, ptime);
798
	gApiLock.Unlock();
799 800
}

801
void Linphone::Core::LinphoneCore::SetUploadPTime(int ptime) 
802
{
803
	gApiLock.Lock();
804
	linphone_core_set_upload_ptime(this->lc, ptime);
805
	gApiLock.Unlock();
806 807
}

808
void Linphone::Core::LinphoneCore::EnableKeepAlive(Platform::Boolean enable)
809
{
810
	gApiLock.Lock();
811
	linphone_core_enable_keep_alive(this->lc, enable);
812
	gApiLock.Unlock();
813 814
}

815
Platform::Boolean Linphone::Core::LinphoneCore::IsKeepAliveEnabled() 
816
{
817
	gApiLock.Lock();
818
	Platform::Boolean enabled = (linphone_core_keep_alive_enabled(this->lc) == TRUE);
819 820
	gApiLock.Unlock();
	return enabled;
821 822
}

823
void Linphone::Core::LinphoneCore::SetPlayFile(Platform::String^ path) 
824
{
825
	gApiLock.Lock();
826 827 828
	const char* file = Linphone::Core::Utils::pstoccs(path);
	linphone_core_set_play_file(this->lc, file);
	delete(file);
829
	gApiLock.Unlock();
830 831
}

832
Platform::Boolean Linphone::Core::LinphoneCore::PauseCall(LinphoneCall^ call) 
833
{
834
	gApiLock.Lock();
835
	Platform::Boolean ok = (linphone_core_pause_call(this->lc, call->call) == 0);
836 837
	gApiLock.Unlock();
	return ok;
838 839
}

840
Platform::Boolean Linphone::Core::LinphoneCore::ResumeCall(LinphoneCall^ call) 
841
{
842
	gApiLock.Lock();
843
	Platform::Boolean ok = (linphone_core_resume_call(this->lc, call->call) == 0);
844 845
	gApiLock.Unlock();
	return ok;
846 847
}

848
Platform::Boolean Linphone::Core::LinphoneCore::PauseAllCalls() 
849
{
850
	gApiLock.Lock();
851
	Platform::Boolean ok = (linphone_core_pause_all_calls(this->lc) == 0);
852 853
	gApiLock.Unlock();
	return ok;
854 855
}

856
Platform::Boolean Linphone::Core::LinphoneCore::IsInConference() 
857
{
858
	gApiLock.Lock();
859
	Platform::Boolean inConference = (linphone_core_is_in_conference(this->lc) == TRUE);
860 861
	gApiLock.Unlock();
	return inConference;
862 863
}

864
Platform::Boolean Linphone::Core::LinphoneCore::EnterConference() 
865
{
866
	gApiLock.Lock();
867
	Platform::Boolean ok = (linphone_core_enter_conference(this->lc) == 0);
868 869
	gApiLock.Unlock();
	return ok;
870 871
}

872
void Linphone::Core::LinphoneCore::LeaveConference() 
873
{
874
	gApiLock.Lock();
875
	linphone_core_leave_conference(this->lc);
876
	gApiLock.Unlock();
877 878
}

879
void Linphone::Core::LinphoneCore::AddToConference(LinphoneCall^ call) 
880
{
881
	gApiLock.Lock();
882
	linphone_core_add_to_conference(this->lc, call->call);
883
	gApiLock.Unlock();
884 885
}

886
void Linphone::Core::LinphoneCore::AddAllToConference() 
887
{
888
	gApiLock.Lock();
889
	linphone_core_add_all_to_conference(this->lc);
890
	gApiLock.Unlock();
891 892
}

893
void Linphone::Core::LinphoneCore::RemoveFromConference(LinphoneCall^ call) 
894
{
895
	gApiLock.Lock();
896
	linphone_core_remove_from_conference(this->lc, call->call);
897
	gApiLock.Unlock();
898 899
}

900
void Linphone::Core::LinphoneCore::TerminateConference() 
901
{
902
	gApiLock.Lock();
903
	linphone_core_terminate_conference(this->lc);
904
	gApiLock.Unlock();
905 906
}

907
int Linphone::Core::LinphoneCore::GetConferenceSize() 
908
{
909 910 911 912
	gApiLock.Lock();
	int size = linphone_core_get_conference_size(this->lc);
	gApiLock.Unlock();
	return size;
913 914
}

915
void Linphone::Core::LinphoneCore::TerminateAllCalls() 
916
{
917
	gApiLock.Lock();
918
	linphone_core_terminate_all_calls(this->lc);
919
	gApiLock.Unlock();
920 921 922 923 924 925 926
}

static void AddCallToVector(void *vCall, void *vector)
{
	::LinphoneCall* c = (::LinphoneCall *)vCall;
	Linphone::Core::RefToPtrProxy<IVector<Object^>^> *list = reinterpret_cast< Linphone::Core::RefToPtrProxy<IVector<Object^>^> *>(vector);
	IVector<Object^>^ calls = (list) ? list->Ref() : nullptr;
927

928 929
	Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(c));
	Linphone::Core::LinphoneCall^ call = (proxy) ? proxy->Ref() : nullptr;
930
	calls->Append(call);
931 932
}

933
IVector<Object^>^ Linphone::Core::LinphoneCore::GetCalls() 
934
{
935
	gApiLock.Lock();
936 937 938 939
	Vector<Object^>^ calls = ref new Vector<Object^>();
	const MSList *callsList = linphone_core_get_calls(this->lc);
	RefToPtrProxy<IVector<Object^>^> *callsPtr = new RefToPtrProxy<IVector<Object^>^>(calls);
	ms_list_for_each2(callsList, AddCallToVector, callsPtr);
940
	gApiLock.Unlock();
941
	return calls;
942 943
}

944
int Linphone::Core::LinphoneCore::GetCallsNb() 
945
{
946 947 948 949
	gApiLock.Lock();
	int nb = linphone_core_get_calls_nb(this->lc);
	gApiLock.Unlock();
	return nb;
950 951
}

952
Linphone::Core::LinphoneCall^ Linphone::Core::LinphoneCore::FindCallFromUri(Platform::String^ uri) 
953
{
954
	gApiLock.Lock();
955 956 957 958 959 960 961 962
	const char *curi = Utils::pstoccs(uri);
	::LinphoneCall *call = const_cast<::LinphoneCall *>(linphone_core_find_call_from_uri(this->lc, curi));
	Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(call));
	Linphone::Core::LinphoneCall^ lCall = (proxy) ? proxy->Ref() : nullptr;
	if (lCall == nullptr) {
		lCall = (Linphone::Core::LinphoneCall^)Linphone::Core::Utils::CreateLinphoneCall(call);
	}
	delete curi;
963
	gApiLock.Unlock();
964
	return lCall;
965 966
}

967
int Linphone::Core::LinphoneCore::GetMaxCalls() 
968
{
969 970 971 972
	gApiLock.Lock();
	int max = linphone_core_get_max_calls(this->lc);
	gApiLock.Unlock();
	return max;
973 974
}

975
void Linphone::Core::LinphoneCore::SetMaxCalls(int max) 
976
{
977
	gApiLock.Lock();
978
	linphone_core_set_max_calls(this->lc, max);
979
	gApiLock.Unlock();
980 981
}

982
Platform::Boolean Linphone::Core::LinphoneCore::IsMyself(Platform::String^ uri) 
983
{
984 985
	gApiLock.Lock();
	Platform::Boolean myself = false;
986
	LinphoneProxyConfig^ lpc = GetDefaultProxyConfig();
987 988 989 990 991
	if (lpc != nullptr) {
		myself = uri->Equals(lpc->GetIdentity());
	}
	gApiLock.Unlock();
	return myself;
992 993
}

994
Platform::Boolean Linphone::Core::LinphoneCore::IsSoundResourcesLocked() 
995
{
996
	gApiLock.Lock();
997
	Platform::Boolean locked = (linphone_core_sound_resources_locked(this->lc) == TRUE);
998 999
	gApiLock.Unlock();
	return locked;
1000 1001
}

Sylvain Berfini's avatar