1 /***************************************************************************
5 * Copyright 2011 Belledonne Communications
7 * Email simon dot morlat at linphone dot org
8 ****************************************************************************/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include "mediastreamer2/msvolume.h"
30 static void conference_check_init(LinphoneConference *ctx){
32 ctx->conf=ms_audio_conference_new();
36 static void remove_local_endpoint(LinphoneConference *ctx){
37 if (ctx->local_endpoint){
38 ms_audio_conference_remove_member(ctx->conf,ctx->local_endpoint);
39 ms_audio_endpoint_release_from_stream(ctx->local_endpoint);
40 ctx->local_endpoint=NULL;
41 audio_stream_stop(ctx->local_participant);
42 ctx->local_participant=NULL;
46 void linphone_core_conference_check_uninit(LinphoneConference *ctx){
48 ms_message("conference_check_uninit(): nmembers=%i",ctx->conf->nmembers);
49 if (ctx->conf->nmembers==1 && ctx->local_participant!=NULL){
50 remove_local_endpoint(ctx);
52 if (ctx->conf->nmembers==0){
53 ms_audio_conference_destroy(ctx->conf);
60 void linphone_call_add_to_conf(LinphoneCall *call){
61 LinphoneCore *lc=call->core;
62 LinphoneConference *conf=&lc->conf_ctx;
64 ep=ms_audio_endpoint_get_from_stream(call->audiostream,TRUE);
65 ms_audio_conference_add_member(conf->conf,ep);
69 void linphone_call_remove_from_conf(LinphoneCall *call){
70 LinphoneCore *lc=call->core;
71 LinphoneConference *conf=&lc->conf_ctx;
73 ms_audio_conference_remove_member(conf->conf,call->endpoint);
74 ms_audio_endpoint_release_from_stream(call->endpoint);
78 static void add_local_endpoint(LinphoneConference *conf,LinphoneCore *lc){
79 /*create a dummy audiostream in order to extract the local part of it */
80 /* network address and ports have no meaning and are not used here. */
81 AudioStream *st=audio_stream_new(65000,FALSE);
82 MSSndCard *playcard=lc->sound_conf.lsd_card ?
83 lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
84 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
86 audio_stream_start_full(st, &av_profile,
96 linphone_core_echo_cancellation_enabled(lc)
98 _post_configure_audio_stream(st,lc,FALSE);
99 conf->local_participant=st;
100 conf->local_endpoint=ms_audio_endpoint_get_from_stream(st,FALSE);
101 ms_audio_conference_add_member(conf->conf,conf->local_endpoint);
104 float linphone_core_get_conference_local_input_volume(LinphoneCore *lc){
105 LinphoneConference *conf=&lc->conf_ctx;
106 AudioStream *st=conf->local_participant;
107 if (st && st->volsend && !conf->local_muted){
109 ms_filter_call_method(st->volsend,MS_VOLUME_GET,&vol);
113 return LINPHONE_VOLUME_DB_LOWEST;
116 int linphone_core_add_to_conference(LinphoneCore *lc, LinphoneCall *call){
117 LinphoneCallParams params;
118 LinphoneConference *conf=&lc->conf_ctx;
120 if (call->current_params.in_conference){
121 ms_error("Already in conference");
124 conference_check_init(&lc->conf_ctx);
125 call->params.in_conference=TRUE;
126 call->params.has_video=FALSE;
128 if (call->state==LinphoneCallPaused)
129 linphone_core_resume_call(lc,call);
130 else if (call->state==LinphoneCallStreamsRunning){
131 /*this will trigger a reINVITE that will later redraw the streams */
132 if (call->audiostream || call->videostream)
133 linphone_call_stop_media_streams (call); /*free the audio & video local resources*/
134 linphone_core_update_call(lc,call,¶ms);
135 add_local_endpoint(conf,lc);
137 ms_error("Call is in state %s, it cannot be added to the conference.",linphone_call_state_to_string(call->state));
143 int linphone_core_remove_from_conference(LinphoneCore *lc, LinphoneCall *call){
145 if (!call->current_params.in_conference){
146 if (call->params.in_conference){
147 ms_warning("Not (yet) in conference, be patient");
150 ms_error("Not in a conference.");
154 call->params.in_conference=FALSE;
155 err=linphone_core_pause_call(lc,call);
159 bool_t linphone_core_is_in_conference(const LinphoneCore *lc){
160 return lc->conf_ctx.local_participant!=NULL;
163 int linphone_core_leave_conference(LinphoneCore *lc){
164 LinphoneConference *conf=&lc->conf_ctx;
165 if (linphone_core_is_in_conference(lc))
166 remove_local_endpoint(conf);
171 int linphone_core_enter_conference(LinphoneCore *lc){
172 LinphoneConference *conf=&lc->conf_ctx;
173 if (conf->local_participant==NULL) add_local_endpoint(conf,lc);
177 int linphone_core_add_all_to_conference(LinphoneCore *lc) {
178 MSList *calls=lc->calls;
180 LinphoneCall *call=(LinphoneCall*)calls->data;
182 if (!call->current_params.in_conference) {
183 linphone_core_add_to_conference(lc, call);
189 int linphone_core_terminate_conference(LinphoneCore *lc) {
190 MSList *calls=lc->calls;
192 LinphoneCall *call=(LinphoneCall*)calls->data;
194 if (call->current_params.in_conference) {
195 linphone_core_terminate_call(lc, call);
201 int linphone_core_get_conference_size(LinphoneCore *lc) {
202 return ms_audio_conference_size(lc->conf_ctx.conf);