]> sjero.net Git - linphone/blob - coreapi/conference.c
e97f2588c2aebc4bf4722d0b0683e5feb79c9a7a
[linphone] / coreapi / conference.c
1 /***************************************************************************
2  *            conference.c
3  *
4  *  Mon Sep 12, 2011
5  *  Copyright  2011  Belledonne Communications
6  *  Author: Simon Morlat
7  *  Email simon dot morlat at linphone dot org
8  ****************************************************************************/
9
10 /*
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.
15  *
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.
20  *
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.
24  */
25  
26 #include "private.h"
27
28
29 static void conference_check_init(LinphoneConference *ctx){
30         if (ctx->conf==NULL){
31                 ctx->conf=ms_audio_conference_new();
32         }
33 }
34
35 static void conference_check_uninit(LinphoneConference *ctx){
36         if (ctx->conf){
37                 if (ctx->conf->nmembers==0){
38                         ms_audio_conference_destroy(ctx->conf);
39                         ctx->conf=NULL;
40                 }
41         }
42 }
43
44
45 void linphone_call_add_to_conf(LinphoneCall *call){
46         LinphoneCore *lc=call->core;
47         LinphoneConference *conf=&lc->conf_ctx;
48         MSAudioEndpoint *ep;
49         ep=ms_audio_endpoint_get_from_stream(call->audiostream,TRUE);
50         ms_audio_conference_add_member(conf->conf,ep);
51         call->endpoint=ep;
52 }
53
54 void linphone_call_remove_from_conf(LinphoneCall *call){
55         LinphoneCore *lc=call->core;
56         LinphoneConference *conf=&lc->conf_ctx;
57         
58         ms_audio_conference_remove_member(conf->conf,call->endpoint);
59         ms_audio_endpoint_release_from_stream(call->endpoint);
60         call->endpoint=NULL;
61         conference_check_uninit(conf);
62 }
63
64 int linphone_core_add_to_conference(LinphoneCore *lc, LinphoneCall *call){
65         LinphoneCallParams params;
66         if (call->current_params.in_conference){
67                 ms_error("Already in conference");
68                 return -1;
69         }
70         conference_check_init(&lc->conf_ctx);
71         call->params.in_conference=TRUE;
72         call->params.has_video=FALSE;
73         params=call->params;
74         if (call->state==LinphoneCallPaused)
75                 linphone_core_resume_call(lc,call);
76         else if (call->state==LinphoneCallStreamsRunning){
77                 /*this will trigger a reINVITE that will later redraw the streams */
78                 linphone_core_update_call(lc,call,&params);
79         }else{
80                 ms_error("Call is in state %s, it cannot be added to the conference.",linphone_call_state_to_string(call->state));
81                 return -1;
82         }
83         return 0;
84 }
85
86 int linphone_core_remove_from_conference(LinphoneCore *lc, LinphoneCall *call){
87         if (!call->current_params.in_conference){
88                 if (call->params.in_conference){
89                         ms_warning("Not (yet) in conference, be patient");
90                         return -1;
91                 }else{
92                         ms_error("Not in a conference.");
93                         return -1;
94                 }
95         }
96         call->params.in_conference=FALSE;
97         return linphone_core_pause_call(lc,call);
98 }
99
100 int linphone_core_pause_conference(LinphoneCore *lc){
101         return 0;
102 }
103
104
105 int linphone_core_resume_conference(LinphoneCore *lc){
106         return 0;
107 }
108