dd4ceff897b241dea264fc8df8386de1a9fca9a8
[asterisk/asterisk.git] / apps / confbridge / include / confbridge.h
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2011, Digium, Inc.
5  *
6  * David Vossel <dvossel@digium.com>
7  * Joshua Colp <jcolp@digium.com>
8  *
9  * See http://www.asterisk.org for more information about
10  * the Asterisk project. Please do not directly contact
11  * any of the maintainers of this project for assistance;
12  * the project provides a web site, mailing lists and IRC
13  * channels for your use.
14  *
15  * This program is free software, distributed under the terms of
16  * the GNU General Public License Version 2. See the LICENSE file
17  * at the top of the source tree.
18  */
19
20
21 #ifndef _CONFBRIDGE_H
22 #define _CONFBRIDGE_H
23
24 #include "asterisk.h"
25 #include "asterisk/app.h"
26 #include "asterisk/logger.h"
27 #include "asterisk/linkedlists.h"
28 #include "asterisk/channel.h"
29 #include "asterisk/bridging.h"
30 #include "asterisk/bridging_features.h"
31
32 /* Maximum length of a conference bridge name */
33 #define MAX_CONF_NAME 32
34 /* Maximum length of a conference pin */
35 #define MAX_PIN     80
36
37 #define DEFAULT_USER_PROFILE "default_user"
38 #define DEFAULT_BRIDGE_PROFILE "default_bridge"
39
40 #define DEFAULT_TALKING_THRESHOLD 160
41 #define DEFAULT_SILENCE_THRESHOLD 2500
42
43 enum user_profile_flags {
44         USER_OPT_ADMIN =        (1 << 0), /*!< Set if the caller is an administrator */
45         USER_OPT_NOONLYPERSON = (1 << 1), /*!< Set if the "you are currently the only person in this conference" sound file should not be played */
46         USER_OPT_MARKEDUSER =   (1 << 2), /*!< Set if the caller is a marked user */
47         USER_OPT_STARTMUTED =   (1 << 3), /*!< Set if the caller should be initially set muted */
48         USER_OPT_MUSICONHOLD =  (1 << 4), /*!< Set if music on hold should be played if nobody else is in the conference bridge */
49         USER_OPT_QUIET =        (1 << 5), /*!< Set if no audio prompts should be played */
50         USER_OPT_ANNOUNCEUSERCOUNT = (1 << 6), /*!< Set if the number of users should be announced to the caller */
51         USER_OPT_WAITMARKED =   (1 << 7), /*!< Set if the user must wait for a marked user before starting */
52         USER_OPT_ENDMARKED =    (1 << 8), /*!< Set if the user should be kicked after the last Marked user exits */
53         USER_OPT_DENOISE =      (1 << 9), /*!< Sets if denoise filter should be used on audio before mixing. */
54         USER_OPT_ANNOUNCE_JOIN_LEAVE = (1 << 10), /*!< Sets if the user's name should be recorded and announced on join and leave. */
55         USER_OPT_TALKER_DETECT = (1 << 11), /*!< Sets if start and stop talking events should generated for this user over AMI. */
56         USER_OPT_DROP_SILENCE =  (1 << 12), /*!< Sets if silence should be dropped from the mix or not. */
57         USER_OPT_DTMF_PASS    =  (1 << 13), /*!< Sets if dtmf should be passed into the conference or not */
58         USER_OPT_ANNOUNCEUSERCOUNTALL = (1 << 14), /*!< Sets if the number of users should be announced to everyone. */
59         USER_OPT_JITTERBUFFER =  (1 << 15), /*!< Places a jitterbuffer on the user. */
60 };
61
62 enum bridge_profile_flags {
63         BRIDGE_OPT_RECORD_CONFERENCE = (1 << 0), /*!< Set if the conference should be recorded */
64         BRIDGE_OPT_VIDEO_SRC_LAST_MARKED = (1 << 1), /*!< Set if conference should feed video of last marked user to all participants. */
65         BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED = (1 << 2), /*!< Set if conference should feed video of first marked user to all participants. */
66         BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER = (1 << 3), /*!< Set if conference set the video feed to follow the loudest talker.  */
67 };
68
69 enum conf_menu_action_id {
70         MENU_ACTION_TOGGLE_MUTE = 1,
71         MENU_ACTION_PLAYBACK,
72         MENU_ACTION_PLAYBACK_AND_CONTINUE,
73         MENU_ACTION_INCREASE_LISTENING,
74         MENU_ACTION_DECREASE_LISTENING,
75         MENU_ACTION_RESET_LISTENING,
76         MENU_ACTION_RESET_TALKING,
77         MENU_ACTION_INCREASE_TALKING,
78         MENU_ACTION_DECREASE_TALKING,
79         MENU_ACTION_DIALPLAN_EXEC,
80         MENU_ACTION_ADMIN_TOGGLE_LOCK,
81         MENU_ACTION_ADMIN_KICK_LAST,
82         MENU_ACTION_LEAVE,
83         MENU_ACTION_NOOP,
84         MENU_ACTION_SET_SINGLE_VIDEO_SRC,
85         MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC,
86         MENU_ACTION_PARTICIPANT_COUNT,
87         MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS,
88 };
89
90 /*! The conference menu action contains both
91  *  the action id that represents the action that
92  *  must take place, along with any data associated
93  *  with that action. */
94 struct conf_menu_action {
95         enum conf_menu_action_id id;
96         union {
97                 char playback_file[PATH_MAX];
98                 struct {
99                         char context[AST_MAX_CONTEXT];
100                         char exten[AST_MAX_EXTENSION];
101                         int priority;
102                 } dialplan_args;
103         } data;
104         AST_LIST_ENTRY(conf_menu_action) action;
105 };
106
107 /*! Conference menu entries contain the DTMF sequence
108  *  and the list of actions that are associated with that
109  *  sequence. */
110 struct conf_menu_entry {
111         /*! the DTMF sequence that triggers the actions */
112         char dtmf[MAXIMUM_DTMF_FEATURE_STRING];
113         /*! The actions associated with this menu entry. */
114         AST_LIST_HEAD_NOLOCK(, conf_menu_action) actions;
115         AST_LIST_ENTRY(conf_menu_entry) entry;
116 };
117
118 /*! Conference menu structure.  Contains a list
119  * of DTMF sequences coupled with the actions those
120  * sequences invoke.*/
121 struct conf_menu {
122         char name[128];
123         int delme;
124         AST_LIST_HEAD_NOLOCK(, conf_menu_entry) entries;
125 };
126
127 struct user_profile {
128         char name[128];
129         char pin[MAX_PIN];
130         char moh_class[128];
131         char announcement[PATH_MAX];
132         unsigned int flags;
133         unsigned int announce_user_count_all_after;
134         /*! The time in ms of talking before a user is considered to be talking by the dsp. */
135         unsigned int talking_threshold;
136         /*! The time in ms of silence before a user is considered to be silent by the dsp. */
137         unsigned int silence_threshold;
138         int delme;
139 };
140
141 enum conf_sounds {
142         CONF_SOUND_HAS_JOINED,
143         CONF_SOUND_HAS_LEFT,
144         CONF_SOUND_KICKED,
145         CONF_SOUND_MUTED,
146         CONF_SOUND_UNMUTED,
147         CONF_SOUND_ONLY_ONE,
148         CONF_SOUND_THERE_ARE,
149         CONF_SOUND_OTHER_IN_PARTY,
150         CONF_SOUND_PLACE_IN_CONF,
151         CONF_SOUND_WAIT_FOR_LEADER,
152         CONF_SOUND_LEADER_HAS_LEFT,
153         CONF_SOUND_GET_PIN,
154         CONF_SOUND_INVALID_PIN,
155         CONF_SOUND_ONLY_PERSON,
156         CONF_SOUND_LOCKED,
157         CONF_SOUND_LOCKED_NOW,
158         CONF_SOUND_UNLOCKED_NOW,
159         CONF_SOUND_ERROR_MENU,
160         CONF_SOUND_JOIN,
161         CONF_SOUND_LEAVE,
162         CONF_SOUND_PARTICIPANTS_MUTED,
163         CONF_SOUND_PARTICIPANTS_UNMUTED,
164 };
165
166 struct bridge_profile_sounds {
167         AST_DECLARE_STRING_FIELDS(
168                 AST_STRING_FIELD(hasjoin);
169                 AST_STRING_FIELD(hasleft);
170                 AST_STRING_FIELD(kicked);
171                 AST_STRING_FIELD(muted);
172                 AST_STRING_FIELD(unmuted);
173                 AST_STRING_FIELD(onlyone);
174                 AST_STRING_FIELD(thereare);
175                 AST_STRING_FIELD(otherinparty);
176                 AST_STRING_FIELD(placeintoconf);
177                 AST_STRING_FIELD(waitforleader);
178                 AST_STRING_FIELD(leaderhasleft);
179                 AST_STRING_FIELD(getpin);
180                 AST_STRING_FIELD(invalidpin);
181                 AST_STRING_FIELD(onlyperson);
182                 AST_STRING_FIELD(locked);
183                 AST_STRING_FIELD(lockednow);
184                 AST_STRING_FIELD(unlockednow);
185                 AST_STRING_FIELD(errormenu);
186                 AST_STRING_FIELD(leave);
187                 AST_STRING_FIELD(join);
188                 AST_STRING_FIELD(participantsmuted);
189                 AST_STRING_FIELD(participantsunmuted);
190         );
191 };
192
193 struct bridge_profile {
194         char name[64];
195         char rec_file[PATH_MAX];
196         unsigned int flags;
197         unsigned int max_members;          /*!< The maximum number of participants allowed in the conference */
198         unsigned int internal_sample_rate; /*!< The internal sample rate of the bridge. 0 when set to auto adjust mode. */
199         unsigned int mix_interval;  /*!< The internal mixing interval used by the bridge. When set to 0 the bridgewill use a default interval. */
200         struct bridge_profile_sounds *sounds;
201         int delme;
202 };
203
204 /*! \brief The structure that represents a conference bridge */
205 struct conference_bridge {
206         char name[MAX_CONF_NAME];                                         /*!< Name of the conference bridge */
207         struct ast_bridge *bridge;                                        /*!< Bridge structure doing the mixing */
208         struct bridge_profile b_profile;                                  /*!< The Bridge Configuration Profile */
209         unsigned int users;                                               /*!< Number of users present */
210         unsigned int markedusers;                                         /*!< Number of marked users present */
211         unsigned int locked:1;                                            /*!< Is this conference bridge locked? */
212         unsigned int muted:1;                                            /*!< Is this conference bridge muted? */
213         struct ast_channel *playback_chan;                                /*!< Channel used for playback into the conference bridge */
214         struct ast_channel *record_chan;                                  /*!< Channel used for recording the conference */
215         pthread_t record_thread;                                          /*!< The thread the recording chan lives in */
216         ast_mutex_t playback_lock;                                        /*!< Lock used for playback channel */
217         AST_LIST_HEAD_NOLOCK(, conference_bridge_user) users_list;        /*!< List of users participating in the conference bridge */
218 };
219
220 /*! \brief The structure that represents a conference bridge user */
221 struct conference_bridge_user {
222         struct conference_bridge *conference_bridge; /*!< Conference bridge they are participating in */
223         struct bridge_profile b_profile;             /*!< The Bridge Configuration Profile */
224         struct user_profile u_profile;               /*!< The User Configuration Profile */
225         char menu_name[64];                          /*!< The name of the DTMF menu assigned to this user */
226         char name_rec_location[PATH_MAX];            /*!< Location of the User's name recorded file if it exists */
227         struct ast_channel *chan;                    /*!< Asterisk channel participating */
228         struct ast_bridge_features features;         /*!< Bridge features structure */
229         struct ast_bridge_tech_optimizations tech_args; /*!< Bridge technology optimizations for talk detection */
230         unsigned int kicked:1;                       /*!< User has been kicked from the conference */
231         unsigned int playing_moh:1;                  /*!< MOH is currently being played to the user */
232         AST_LIST_ENTRY(conference_bridge_user) list; /*!< Linked list information */
233 };
234
235 /*! \brief load confbridge.conf file */
236 int conf_load_config(int reload);
237
238 /*! \brief destroy the information loaded from the confbridge.conf file*/
239 void conf_destroy_config(void);
240
241 /*!
242  * \brief find a user profile given a user profile's name and store
243  * that profile in result structure.
244  *
245  * \details This function first attempts to find any custom user
246  * profile that might exist on a channel datastore, if that doesn't
247  * exist it looks up the provided user profile name, if that doesn't
248  * exist either the default_user profile is used.
249
250  * \retval user profile on success
251  * \retval NULL on failure
252  */
253 const struct user_profile *conf_find_user_profile(struct ast_channel *chan, const char *user_profile_name, struct user_profile *result);
254
255 /*!
256  * \brief Find a bridge profile
257  *
258  * \details Any bridge profile found using this function must be
259  * destroyed using conf_bridge_profile_destroy.  This function first
260  * attempts to find any custom bridge profile that might exist on
261  * a channel datastore, if that doesn't exist it looks up the
262  * provided bridge profile name, if that doesn't exist either
263  * the default_bridge profile is used.
264  *
265  * \retval Bridge profile on success
266  * \retval NULL on failure
267  */
268 const struct bridge_profile *conf_find_bridge_profile(struct ast_channel *chan, const char *bridge_profile_name, struct bridge_profile *result);
269
270 /*!
271  * \brief Destroy a bridge profile found by 'conf_find_bridge_profile'
272  */
273 void conf_bridge_profile_destroy(struct bridge_profile *b_profile);
274
275 /*!
276  * \brief copies a bridge profile
277  * \note conf_bridge_profile_destroy must be called on the dst structure
278  */
279 void conf_bridge_profile_copy(struct bridge_profile *dst, struct bridge_profile *src);
280
281 /*!
282  * \brief Set a DTMF menu to a conference user by menu name.
283  *
284  * \retval 0 on success, menu was found and set
285  * \retval -1 on error, menu was not found
286  */
287 int conf_set_menu_to_user(const char *menu_name, struct conference_bridge_user *conference_bridge_user);
288
289 /*!
290  * \brief Finds a menu_entry in a menu structure matched by DTMF sequence.
291  *
292  * \note the menu entry found must be destroyed using conf_menu_entry_destroy()
293  *
294  * \retval 1 success, entry is found and stored in result
295  * \retval 0 failure, no entry found for given DTMF sequence
296  */
297 int conf_find_menu_entry_by_sequence(const char *dtmf_sequence, struct conf_menu *menu, struct conf_menu_entry *result);
298
299 /*!
300  * \brief Destroys and frees all the actions stored in a menu_entry structure
301  */
302 void conf_menu_entry_destroy(struct conf_menu_entry *menu_entry);
303
304 /*!
305  * \brief Once a DTMF sequence matches a sequence in the user's DTMF menu, this function will get
306  * called to perform the menu action.
307  *
308  * \param bridge_channel, Bridged channel this is involving
309  * \param conference_bridge_user, the conference user to perform the action on.
310  * \param menu_entry, the menu entry that invoked this callback to occur.
311  * \param menu, an AO2 referenced pointer to the entire menu structure the menu_entry
312  *        derived from.
313  *
314  * \note The menu_entry is a deep copy of the entry found in the menu structure.  This allows
315  * for the menu_entry to be accessed without requiring the menu lock.  If the menu must
316  * be accessed, the menu lock must be held.  Reference counting of the menu structure is
317  * handled outside of the scope of this function.
318  *
319  * \retval 0 success
320  * \retval -1 failure
321  */
322 int conf_handle_dtmf(
323         struct ast_bridge_channel *bridge_channel,
324         struct conference_bridge_user *conference_bridge_user,
325         struct conf_menu_entry *menu_entry,
326         struct conf_menu *menu);
327
328
329 /*! \brief Looks to see if sound file is stored in bridge profile sounds, if not
330  *  default sound is provided.*/
331 const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds *custom_sounds);
332
333 int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value);
334 #endif