1 /*
2  * Copyright (C) 2002-2003 Fhg Fokus
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * For a license to use the sems software under conditions
12  * other than those described here, or to purchase support for this
13  * software, please contact iptel.org by e-mail at the following addresses:
14  *    info@iptel.org
15  *
16  * SEMS 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 /** @file AmConferenceStatus.h */
26 #ifndef _ConferenceStatus_h_
27 #define _ConferenceStatus_h_
28 
29 #include "AmThread.h"
30 #include "AmRtpStream.h"
31 #include "AmMultiPartyMixer.h"
32 #include "AmEventQueue.h"
33 
34 #include <map>
35 #include <string>
36 using std::string;
37 
38 class AmConferenceChannel;
39 
40 enum { ConfNewParticipant = 1,
41        ConfParticipantLeft };
42 
43 /** \brief event in a conference*/
44 struct ConferenceEvent: public AmEvent
45 {
46   unsigned int participants;
47   string       conf_id;
48   string       sess_id;
49 
ConferenceEventConferenceEvent50   ConferenceEvent(int event_id,
51 		  unsigned int participants,
52 		  const string& conf_id,
53 		  const string& sess_id)
54     : AmEvent(event_id),
55       participants(participants),
56       conf_id(conf_id),
57       sess_id(sess_id)
58   {}
59 };
60 
61 /**
62  * \brief One conference (room).
63  *
64  * The ConferenceStatus manages one conference.
65  */
66 class AmConferenceStatus
67 {
68   static std::map<string,AmConferenceStatus*> cid2status;
69   static AmMutex                         cid2s_mut;
70 
71   struct SessInfo {
72 
73     string       sess_id;
74     unsigned int ch_id;
75 
SessInfoSessInfo76     SessInfo(const string& local_tag,
77 	     unsigned int  ch_id)
78       : sess_id(local_tag),
79 	ch_id(ch_id)
80     {}
81   };
82 
83   string                 conf_id;
84   AmMultiPartyMixer      mixer;
85 
86   // sess_id -> ch_id
87   std::map<string, unsigned int> sessions;
88 
89   // ch_id -> sess_id
90   std::map<unsigned int, SessInfo*> channels;
91 
92   AmMutex                      sessions_mut;
93 
94   AmConferenceStatus(const string& conference_id);
95   ~AmConferenceStatus();
96 
97   AmConferenceChannel* getChannel(const string& sess_id, int input_sample_rate);
98 
99   int releaseChannel(unsigned int ch_id);
100 
101   void postConferenceEvent(int event_id, const string& sess_id);
102 
103 public:
getConfID()104   const string&      getConfID() { return conf_id; }
getMixer()105   AmMultiPartyMixer* getMixer()  { return &mixer; }
106 
107   static AmConferenceChannel* getChannel(const string& cid,
108 					 const string& local_tag,
109                                          int input_sample_rate);
110 
111   static void releaseChannel(const string& cid, unsigned int ch_id);
112 
113   static void postConferenceEvent(const string& cid, int event_id,
114 				  const string& sess_id);
115 
116   static size_t getConferenceSize(const string& cid);
117 };
118 
119 #endif
120 // Local Variables:
121 // mode:C++
122 // End:
123 
124