conference.cc 22.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*******************************************************************************
 *            conference.cc
 *
 *  Thu Nov 26, 2015
 *  Copyright  2015  Belledonne Communications
 *  Author: Linphone's team
 *  Email info@belledonne-communications.com
 ******************************************************************************/

/*
 *  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 "private.h"
#include "conference.h"
#include <mediastreamer2/msvolume.h>
29
#include <typeinfo>
30 31 32 33

namespace Linphone {
class Conference {
public:
34
	Conference(LinphoneCore *core);
35 36 37 38 39 40
	virtual ~Conference() {};
	
	virtual int addCall(LinphoneCall *call) = 0;
	virtual int removeCall(LinphoneCall *call) = 0;
	virtual int terminate() = 0;
	
41 42 43 44 45 46 47 48
	virtual int enter() = 0;
	virtual int leave() = 0;
	virtual bool isIn() const = 0;
	
	AudioStream *getAudioStream() const {return m_localParticipantStream;}
	int muteMicrophone(bool val);
	bool microphoneIsMuted() const {return m_isMuted;}
	float getInputVolume() const;
49 50 51 52 53 54 55 56 57 58 59 60
	
	virtual int getParticipantCount() const = 0;
	
	virtual int startRecording(const char *path) = 0;
	virtual int stopRecording() = 0;
	
	virtual void onCallStreamStarting(LinphoneCall *call, bool isPausedByRemote) {};
	virtual void onCallStreamStopping(LinphoneCall *call) {};
	virtual void onCallTerminating(LinphoneCall *call) {};
	
protected:
	LinphoneCore *m_core;
61 62
	AudioStream *m_localParticipantStream;
	bool m_isMuted;
63 64 65 66 67
};
};

using namespace Linphone;

68
Conference::Conference(LinphoneCore *core) :
69
	m_core(core),
70 71 72 73
	m_localParticipantStream(NULL),
	m_isMuted(false) {
}

74 75 76 77 78 79 80 81 82 83
int Conference::addCall(LinphoneCall *call) {
	call->conf_ref = (LinphoneConference *)this;
	return 0;
}

int Conference::removeCall(LinphoneCall *call) {
	call->conf_ref = NULL;
	return 0;
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
int Conference::muteMicrophone(bool val)  {
	if (val) {
		audio_stream_set_mic_gain(m_localParticipantStream, 0);
	} else {
		audio_stream_set_mic_gain_db(m_localParticipantStream, m_core->sound_conf.soft_mic_lev);
	}
	if ( linphone_core_get_rtp_no_xmit_on_audio_mute(m_core) ){
		audio_stream_mute_rtp(m_localParticipantStream, val);
	}
	m_isMuted=val;
	return 0;
}

float Conference::getInputVolume() const {
	AudioStream *st=m_localParticipantStream;
	if (st && st->volsend && !m_isMuted){
		float vol=0;
		ms_filter_call_method(st->volsend,MS_VOLUME_GET,&vol);
		return vol;

	}
	return LINPHONE_VOLUME_DB_LOWEST;
106 107 108 109
}


namespace Linphone {
110
class LocalConference: public Conference {
111
public:
112 113
	LocalConference(LinphoneCore *core);
	virtual ~LocalConference();
114 115 116 117 118
	
	virtual int addCall(LinphoneCall *call);
	virtual int removeCall(LinphoneCall *call);
	virtual int terminate();
	
119 120 121
	virtual int enter();
	virtual int leave();
	virtual bool isIn() const {return m_localParticipantStream!=NULL;}
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
	virtual int getParticipantCount() const;
	
	virtual int startRecording(const char *path);
	virtual int stopRecording();
	
	void onCallStreamStarting(LinphoneCall *call, bool isPausedByRemote);
	void onCallStreamStopping(LinphoneCall *call);
	void onCallTerminating(LinphoneCall *call);
	
private:
	void addLocalEndpoint();
	int remoteParticipantsCount();
	void removeLocalEndpoint();
	int removeFromConference(LinphoneCall *call, bool_t active);
	int convertConferenceToCall();
	static RtpProfile *sMakeDummyProfile(int samplerate);

	MSAudioConference *m_conf;
	MSAudioEndpoint *m_localEndpoint;
	MSAudioEndpoint *m_recordEndpoint;
	RtpProfile *m_localDummyProfile;
	bool_t m_terminated;
};
};

147
LocalConference::LocalConference(LinphoneCore *core): Conference(core),
148 149 150 151 152 153 154 155 156 157
	m_conf(NULL),
	m_localEndpoint(NULL),
	m_recordEndpoint(NULL),
	m_localDummyProfile(NULL),
	m_terminated(FALSE) {
	MSAudioConferenceParams params;
	params.samplerate = lp_config_get_int(m_core->config, "sound","conference_rate",16000);
	m_conf=ms_audio_conference_new(&params);
}

158
LocalConference::~LocalConference() {
159 160 161
	if(m_conf) terminate();
}

162
RtpProfile *LocalConference::sMakeDummyProfile(int samplerate){
163 164 165 166 167 168 169
	RtpProfile *prof=rtp_profile_new("dummy");
	PayloadType *pt=payload_type_clone(&payload_type_l16_mono);
	pt->clock_rate=samplerate;
	rtp_profile_set_payload(prof,0,pt);
	return prof;
}

170
void LocalConference::addLocalEndpoint() {
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	/*create a dummy audiostream in order to extract the local part of it */
	/* network address and ports have no meaning and are not used here. */
	AudioStream *st=audio_stream_new(65000,65001,FALSE);
	MSSndCard *playcard=m_core->sound_conf.lsd_card ?
			m_core->sound_conf.lsd_card : m_core->sound_conf.play_sndcard;
	MSSndCard *captcard=m_core->sound_conf.capt_sndcard;
	const MSAudioConferenceParams *params=ms_audio_conference_get_params(m_conf);
	m_localDummyProfile=sMakeDummyProfile(params->samplerate);

	audio_stream_start_full(st, m_localDummyProfile,
				"127.0.0.1",
				65000,
				"127.0.0.1",
				65001,
				0,
				40,
				NULL,
				NULL,
				playcard,
				captcard,
				linphone_core_echo_cancellation_enabled(m_core)
				);
	_post_configure_audio_stream(st,m_core,FALSE);
194
	m_localParticipantStream=st;
195 196 197 198
	m_localEndpoint=ms_audio_endpoint_get_from_stream(st,FALSE);
	ms_audio_conference_add_member(m_conf,m_localEndpoint);
}

199
int LocalConference::addCall(LinphoneCall *call) {
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	if (call->current_params->in_conference){
		ms_error("Already in conference");
		return -1;
	}

	if (call->state==LinphoneCallPaused){
		call->params->in_conference=TRUE;
		call->params->has_video=FALSE;
		linphone_core_resume_call(m_core,call);
	}else if (call->state==LinphoneCallStreamsRunning){
		LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call));
		params->in_conference=TRUE;
		params->has_video=FALSE;

		if (call->audiostream || call->videostream){
			linphone_call_stop_media_streams(call); /*free the audio & video local resources*/
			linphone_call_init_media_streams(call);
		}
		if (call==m_core->current_call){
			m_core->current_call=NULL;
		}
		/*this will trigger a reINVITE that will later redraw the streams */
		/*FIXME probably a bit too much to just redraw streams !*/
		linphone_core_update_call(m_core,call,params);
		linphone_call_params_destroy(params);
		addLocalEndpoint();
	}else{
		ms_error("Call is in state %s, it cannot be added to the conference.",linphone_call_state_to_string(call->state));
		return -1;
	}
230
	Conference::addCall(call);
231 232 233
	return 0;
}

234
int LocalConference::removeFromConference(LinphoneCall *call, bool_t active){
235 236 237 238 239 240 241 242 243 244 245 246 247
	int err=0;
	char *str;

	if (!call->current_params->in_conference){
		if (call->params->in_conference){
			ms_warning("Not (yet) in conference, be patient");
			return -1;
		}else{
			ms_error("Not in a conference.");
			return -1;
		}
	}
	call->params->in_conference=FALSE;
248
	Conference::removeCall(call);
249 250 251 252 253 254 255 256

	str=linphone_call_get_remote_address_as_string(call);
	ms_message("%s will be removed from conference", str);
	ms_free(str);
	if (active){
		LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call));
		params->in_conference=FALSE;
		// reconnect local audio with this call
257
		if (isIn()){
258
			ms_message("Leaving conference for reconnecting with unique call.");
259
			leave();
260 261 262 263 264 265 266 267 268 269 270
		}
		ms_message("Updating call to actually remove from conference");
		err=linphone_core_update_call(m_core,call,params);
		linphone_call_params_destroy(params);
	} else{
		ms_message("Pausing call to actually remove from conference");
		err=_linphone_core_pause_call(m_core,call);
	}
	return err;
}

271
int LocalConference::remoteParticipantsCount() {
272 273
	int count=getParticipantCount();
	if (count==0) return 0;
274
	if (!m_localParticipantStream) return count;
275 276 277
	return count -1;
}

278
int LocalConference::convertConferenceToCall(){
279 280 281 282 283 284 285 286 287 288 289 290
	int err=0;
	MSList *calls=m_core->calls;

	if (remoteParticipantsCount()!=1){
		ms_error("No unique call remaining in conference.");
		return -1;
	}

	while (calls) {
		LinphoneCall *rc=(LinphoneCall*)calls->data;
		calls=calls->next;
		if (rc->params->in_conference) { // not using current_param
291
			bool_t active_after_removed=isIn();
292 293 294 295 296 297 298
			err=removeFromConference(rc, active_after_removed);
			break;
		}
	}
	return err;
}

299
int LocalConference::removeCall(LinphoneCall *call) {
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
	int err;
	char * str=linphone_call_get_remote_address_as_string(call);
	ms_message("Removing call %s from the conference", str);
	ms_free(str);
	err=removeFromConference(call, FALSE);
	if (err){
		ms_error("Error removing participant from conference.");
		return err;
	}

	if (remoteParticipantsCount()==1){
		ms_message("conference size is 1: need to be converted to plain call");
		err=convertConferenceToCall();
	} else {
		ms_message("the conference need not to be converted as size is %i", remoteParticipantsCount());
	}
	return err;
}

319
int LocalConference::terminate() {
320 321 322 323 324 325 326 327 328 329 330 331 332
	MSList *calls=m_core->calls;
	m_terminated=TRUE;

	while (calls) {
		LinphoneCall *call=(LinphoneCall*)calls->data;
		calls=calls->next;
		if (call->current_params->in_conference) {
			linphone_core_terminate_call(m_core, call);
		}
	}
	return 0;
}

333
int LocalConference::enter() {
334 335 336 337 338 339
	if (linphone_core_sound_resources_locked(m_core)) {
		return -1;
	}
	if (m_core->current_call != NULL) {
		_linphone_core_pause_call(m_core, m_core->current_call);
	}
340
	if (m_localParticipantStream==NULL) addLocalEndpoint();
341 342 343
	return 0;
}

344
void LocalConference::removeLocalEndpoint(){
345 346 347 348
	if (m_localEndpoint){
		ms_audio_conference_remove_member(m_conf,m_localEndpoint);
		ms_audio_endpoint_release_from_stream(m_localEndpoint);
		m_localEndpoint=NULL;
349 350
		audio_stream_stop(m_localParticipantStream);
		m_localParticipantStream=NULL;
351 352 353 354
		rtp_profile_destroy(m_localDummyProfile);
	}
}

355
int LocalConference::leave() {
356
	if (isIn())
357 358 359 360
		removeLocalEndpoint();
	return 0;
}

361
int LocalConference::getParticipantCount() const {
362 363 364 365 366 367
	if (m_conf == NULL) {
		return 0;
	}
	return ms_audio_conference_get_size(m_conf) - (m_recordEndpoint ? 1 : 0);
}

368
int LocalConference::startRecording(const char *path) {
369 370 371 372 373 374 375 376 377 378 379 380
	if (m_conf == NULL) {
		ms_warning("linphone_core_start_conference_recording(): no conference now.");
		return -1;
	}
	if (m_recordEndpoint==NULL){
		m_recordEndpoint=ms_audio_endpoint_new_recorder();
		ms_audio_conference_add_member(m_conf,m_recordEndpoint);
	}
	ms_audio_recorder_endpoint_start(m_recordEndpoint,path);
	return 0;
}

381
int LocalConference::stopRecording() {
382 383 384 385 386 387 388 389 390 391 392 393
	if (m_conf == NULL) {
		ms_warning("linphone_core_stop_conference_recording(): no conference now.");
		return -1;
	}
	if (m_recordEndpoint==NULL){
		ms_warning("linphone_core_stop_conference_recording(): no record active.");
		return -1;
	}
	ms_audio_recorder_endpoint_stop(m_recordEndpoint);
	return 0;
}

394
void LocalConference::onCallStreamStarting(LinphoneCall *call, bool isPausedByRemote) {
395 396 397 398 399 400 401 402
	call->params->has_video = FALSE;
	call->camera_enabled = FALSE;
	MSAudioEndpoint *ep=ms_audio_endpoint_get_from_stream(call->audiostream,TRUE);
	ms_audio_conference_add_member(m_conf,ep);
	ms_audio_conference_mute_member(m_conf,ep,isPausedByRemote);
	call->endpoint=ep;
}

403
void LocalConference::onCallStreamStopping(LinphoneCall *call) {
404 405 406 407 408
	ms_audio_conference_remove_member(m_conf,call->endpoint);
	ms_audio_endpoint_release_from_stream(call->endpoint);
	call->endpoint=NULL;
}

409
void LocalConference::onCallTerminating(LinphoneCall *call) {
410 411 412 413 414 415
	int remote_count=remoteParticipantsCount();
	ms_message("conference_check_uninit(): size=%i", getParticipantCount());
	if (remote_count==1 && !m_terminated){
		convertConferenceToCall();
	}
	if (remote_count==0){
416
		if (m_localParticipantStream)
417 418 419 420 421 422 423 424 425 426 427 428 429
			removeLocalEndpoint();
		if (m_recordEndpoint){
			ms_audio_conference_remove_member(m_conf, m_recordEndpoint);
			ms_audio_endpoint_destroy(m_recordEndpoint);
		}
	}
	if (ms_audio_conference_get_size(m_conf)==0){
		ms_audio_conference_destroy(m_conf);
		m_core->conf_ctx = NULL;
		delete this;
	}
}

430
namespace Linphone {
431
class RemoteConference: public Conference {
432
public:
433 434
	RemoteConference(LinphoneCore *core);
	virtual ~RemoteConference();
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
	
	virtual int addCall(LinphoneCall *call);
	virtual int removeCall(LinphoneCall *call) {return 0;}
	virtual int terminate();
	
	virtual int enter();
	virtual int leave();
	virtual bool isIn() const;
	virtual int getParticipantCount() const {return -1;}
	
	virtual int startRecording(const char *path) {return 0;}
	virtual int stopRecording() {return 0;}

private:
	enum State {
		NotConnectedToFocus,
		ConnectingToFocus,
		ConnectedToFocus,
	};
	static const char *stateToString(State state);
	
	void onFocusCallSateChanged(LinphoneCallState state);
	void onPendingCallStateChanged(LinphoneCall *call, LinphoneCallState state);
	
	static void callStateChangedCb(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message);
	static void transferStateChanged(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state);
	
	const char *m_focusAddr;
463
	char *m_focusContact;
464 465 466 467 468 469 470 471
	LinphoneCall *m_focusCall;
	State m_state;
	LinphoneCoreVTable *m_vtable;
	MSList *m_pendingCalls;
	MSList *m_transferingCalls;
};
};

472
RemoteConference::RemoteConference(LinphoneCore *core):
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
	Conference(core),
	m_focusAddr(NULL),
	m_focusContact(NULL),
	m_focusCall(NULL),
	m_state(NotConnectedToFocus),
	m_vtable(NULL),
	m_pendingCalls(NULL),
	m_transferingCalls(NULL) {
	m_focusAddr = lp_config_get_string(m_core->config, "misc", "conference_focus_addr", "");
	m_vtable = linphone_core_v_table_new();
	m_vtable->call_state_changed = callStateChangedCb;
	m_vtable->transfer_state_changed = transferStateChanged;
	linphone_core_v_table_set_user_data(m_vtable, this);
	linphone_core_add_listener(m_core, m_vtable);
}

489
RemoteConference::~RemoteConference() {
490
	if(m_state == ConnectedToFocus) terminate();
491 492 493 494
	linphone_core_remove_listener(m_core, m_vtable);
	linphone_core_v_table_destroy(m_vtable);
}

495
int RemoteConference::addCall(LinphoneCall *call) {
496 497 498 499
	LinphoneAddress *addr;
	
	switch(m_state) {
		case NotConnectedToFocus:
500
			Conference::addCall(call);
501 502 503
			ms_message("Calling the conference focus (%s)", m_focusAddr);
			addr = linphone_address_new(m_focusAddr);
			if(addr) {
504
				m_focusCall = linphone_call_ref(linphone_core_invite_address(m_core, addr));
505
				m_localParticipantStream = m_focusCall->audiostream;
506
				m_pendingCalls = ms_list_append(m_pendingCalls, linphone_call_ref(call));
507 508 509 510 511
				m_state = ConnectingToFocus;
				linphone_address_unref(addr);
				return 0;
			} else return -1;

512 513 514 515 516
		case ConnectingToFocus:
			Conference::addCall(call);
			m_pendingCalls = ms_list_append(m_pendingCalls, linphone_call_ref(call));
			return 0;
			
517
		case ConnectedToFocus:
518 519
			Conference::addCall(call);
			m_transferingCalls = ms_list_append(m_transferingCalls, linphone_call_ref(call));
520 521 522 523 524 525 526 527 528
			linphone_core_transfer_call(m_core, call, m_focusContact);
			return 0;

		default:
			ms_error("Could not add call %p to the conference. Bad conference state (%s)", call, stateToString(m_state));
			return -1;
	}
}

529
int RemoteConference::terminate() {
530 531 532
	switch(m_state) {
		case ConnectingToFocus:
		case ConnectedToFocus:
533
			Conference::removeCall(m_focusCall);
534 535 536 537 538 539 540 541
			linphone_core_terminate_call(m_core, m_focusCall);
			break;
		default:
			break;
	}
	return 0;
}

542
int RemoteConference::enter() {
543
	if(m_state != ConnectedToFocus) {
François Grisez's avatar
François Grisez committed
544
		ms_error("Could not enter in the conference: bad conference state (%s)", stateToString(m_state));
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
		return -1;
	}
	LinphoneCallState callState = linphone_call_get_state(m_focusCall);
	switch(callState) {
		case LinphoneCallStreamsRunning: break;
		case LinphoneCallPaused:
			linphone_core_resume_call(m_core, m_focusCall);
			break;
		default:
			ms_error("Could not join the conference: bad focus call state (%s)", linphone_call_state_to_string(callState));
			return -1;
	}
	return 0;
}

560
int RemoteConference::leave() {
561
	if(m_state != ConnectedToFocus) {
François Grisez's avatar
François Grisez committed
562
		ms_error("Could not leave the conference: bad conference state (%s)", stateToString(m_state));
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
		return -1;
	}
	LinphoneCallState callState = linphone_call_get_state(m_focusCall);
	switch(callState) {
		case LinphoneCallPaused: break;
		case LinphoneCallStreamsRunning:
			linphone_core_pause_call(m_core, m_focusCall);
			break;
		default:
			ms_error("Could not leave the conference: bad focus call state (%s)", linphone_call_state_to_string(callState));
			return -1;
	}
	return 0;
}

578
bool RemoteConference::isIn() const {
579 580 581 582 583
	if(m_state != ConnectedToFocus) return false;
	LinphoneCallState callState = linphone_call_get_state(m_focusCall);
	return callState == LinphoneCallStreamsRunning;
}

584
const char *RemoteConference::stateToString(RemoteConference::State state) {
585 586 587 588 589 590 591 592
	switch(state) {
		case NotConnectedToFocus: return "NotConnectedToFocus";
		case ConnectingToFocus: return "ConnectingToFocus";
		case ConnectedToFocus: return "ConnectedToFocus";
		default: return "Unknown";
	}
}

593
void RemoteConference::onFocusCallSateChanged(LinphoneCallState state) {
594 595
	MSList *it;
	
596
	switch (state) {
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
		case LinphoneCallConnected:
			m_state = ConnectedToFocus;
			m_focusContact = ms_strdup(linphone_call_get_remote_contact(m_focusCall));
			it = m_pendingCalls;
			while (it) {
				LinphoneCall *pendingCall = (LinphoneCall *)it->data;
				LinphoneCallState pendingCallState = linphone_call_get_state(pendingCall);
				if(pendingCallState == LinphoneCallStreamsRunning || pendingCallState == LinphoneCallPaused) {
					MSList *current_elem = it;
					it = it->next;
					m_pendingCalls = ms_list_remove_link(m_pendingCalls, current_elem);
					m_transferingCalls = ms_list_append(m_transferingCalls, pendingCall);
					linphone_core_transfer_call(m_core, pendingCall, m_focusContact);
				} else {
					it = it->next;
612
				}
613 614
			}
			break;
615

616 617 618 619 620 621 622 623 624
		case LinphoneCallError:
		case LinphoneCallEnd:
			Conference::removeCall(m_focusCall);
			m_state = NotConnectedToFocus;
			linphone_call_unref(m_focusCall);
			m_focusCall = NULL;
			m_localParticipantStream = NULL;
			if(m_focusContact) {
				ms_free(m_focusContact);
625
				m_focusContact = NULL;
626 627 628 629
			}
			m_pendingCalls = ms_list_free_with_data(m_pendingCalls, (void (*)(void *))linphone_call_unref);
			m_transferingCalls = ms_list_free_with_data(m_transferingCalls, (void (*)(void *))linphone_call_unref);
			break;
630

631 632
		default: break;
	}
633 634
}

635
void RemoteConference::onPendingCallStateChanged(LinphoneCall *call, LinphoneCallState state) {
636 637 638 639
	switch(state) {
			case LinphoneCallStreamsRunning:
			case LinphoneCallPaused:
				if(m_state == ConnectedToFocus) {
François Grisez's avatar
François Grisez committed
640 641
					m_pendingCalls = ms_list_remove(m_pendingCalls, call);
					m_transferingCalls = ms_list_append(m_transferingCalls, call);
642
					linphone_core_transfer_call(m_core, call, m_focusContact);
643 644 645 646 647
				}
				break;
				
			case LinphoneCallError:
			case LinphoneCallEnd:
648
				Conference::removeCall(call);
François Grisez's avatar
François Grisez committed
649
				m_pendingCalls = ms_list_remove(m_pendingCalls, call);
650
				linphone_call_unref(call);
651 652 653 654 655 656
				break;
				
			default: break;
		}
}

657
void RemoteConference::callStateChangedCb(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message) {
658
	LinphoneCoreVTable *vtable = linphone_core_get_current_vtable(lc);
659
	RemoteConference *conf = (RemoteConference *)linphone_core_v_table_get_user_data(vtable);
660 661 662 663 664 665 666
	if (call == conf->m_focusCall) {
		conf->onFocusCallSateChanged(cstate);
	} else if(ms_list_find(conf->m_pendingCalls, call)) {
		conf->onPendingCallStateChanged(call, cstate);
	}
}

667
void RemoteConference::transferStateChanged(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state) {
668
	LinphoneCoreVTable *vtable = linphone_core_get_current_vtable(lc);
669
	RemoteConference *conf = (RemoteConference *)linphone_core_v_table_get_user_data(vtable);
670 671 672 673 674
	if (ms_list_find(conf->m_transferingCalls, transfered)) {
		switch (new_call_state) {
			case LinphoneCallConnected:
			case LinphoneCallError:
				conf->m_transferingCalls = ms_list_remove(conf->m_transferingCalls, transfered);
675
				linphone_call_unref(transfered);
676 677 678 679 680 681 682 683 684 685 686
				break;

			default:
				break;
		}
	}
}




687 688
LinphoneConference *linphone_local_conference_new(LinphoneCore *core) {
	return (LinphoneConference *) new LocalConference(core);
689 690
}

691 692
LinphoneConference *linphone_remote_conference_new(LinphoneCore *core) {
	return (LinphoneConference *) new RemoteConference(core);
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
}

void linphone_conference_free(LinphoneConference *obj) {
	delete (Conference *)obj;
}

int linphone_conference_add_call(LinphoneConference *obj, LinphoneCall *call) {
	return ((Conference *)obj)->addCall(call);
}

int linphone_conference_remove_call(LinphoneConference *obj, LinphoneCall *call) {
	return ((Conference *)obj)->removeCall(call);
}

int linphone_conference_terminate(LinphoneConference *obj) {
	return ((Conference *)obj)->terminate();
}

int linphone_conference_add_local_participant(LinphoneConference *obj) {
712
	return ((Conference *)obj)->enter();
713 714 715
}

int linphone_conference_remove_local_participant(LinphoneConference *obj) {
716
	return ((Conference *)obj)->leave();
717 718 719
}

bool_t linphone_conference_local_participant_is_in(const LinphoneConference *obj) {
720
	return ((Conference *)obj)->isIn() ? TRUE : FALSE;
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
}

AudioStream *linphone_conference_get_audio_stream(const LinphoneConference *obj) {
	return ((Conference *)obj)->getAudioStream();
}

int linphone_conference_mute_microphone(LinphoneConference *obj, bool_t val) {
	return ((Conference *)obj)->muteMicrophone(val);
}

bool_t linphone_conference_microphone_is_muted(const LinphoneConference *obj) {
	return ((Conference *)obj)->microphoneIsMuted();
}

float linphone_conference_get_input_volume(const LinphoneConference *obj) {
	return ((Conference *)obj)->getInputVolume();
}

int linphone_conference_get_participant_count(const LinphoneConference *obj) {
	return ((Conference *)obj)->getParticipantCount();
}

int linphone_conference_start_recording(LinphoneConference *obj, const char *path) {
	return ((Conference *)obj)->startRecording(path);
}

int linphone_conference_stop_recording(LinphoneConference *obj) {
	return ((Conference *)obj)->stopRecording();
}

void linphone_conference_on_call_stream_starting(LinphoneConference *obj, LinphoneCall *call, bool_t is_paused_by_remote) {
	((Conference *)obj)->onCallStreamStarting(call, is_paused_by_remote);
}

void linphone_conference_on_call_stream_stopping(LinphoneConference *obj, LinphoneCall *call) {
	((Conference *)obj)->onCallStreamStopping(call);
}

void linphone_conference_on_call_terminating(LinphoneConference *obj, LinphoneCall *call) {
	((Conference *)obj)->onCallTerminating(call);
}
762 763 764

bool_t linphone_conference_check_class(LinphoneConference *obj, LinphoneConferenceClass _class) {
	switch(_class) {
765 766
		case LinphoneConferenceClassLocal: return typeid(obj) == typeid(LocalConference);
		case LinphoneConferenceClassRemote: return typeid(obj) == typeid(RemoteConference);
767 768 769
		default: return FALSE;
	}
}