d3ead35a3e503c3c98cbceec9744a102fc5f149d
[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         AST_LIST_HEAD_NOLOCK(, conf_menu_entry) entries;
124 };
125
126 struct user_profile {
127         char name[128];
128         char pin[MAX_PIN];
129         char moh_class[128];
130         char announcement[PATH_MAX];
131         unsigned int flags;
132         unsigned int announce_user_count_all_after;
133         /*! The time in ms of talking before a user is considered to be talking by the dsp. */
134         unsigned int talking_threshold;
135         /*! The time in ms of silence before a user is considered to be silent by the dsp. */
136         unsigned int silence_threshold;
137 };
138
139 enum conf_sounds {
140         CONF_SOUND_HAS_JOINED,
141         CONF_SOUND_HAS_LEFT,
142         CONF_SOUND_KICKED,
143         CONF_SOUND_MUTED,
144         CONF_SOUND_UNMUTED,
145         CONF_SOUND_ONLY_ONE,
146         CONF_SOUND_THERE_ARE,
147         CONF_SOUND_OTHER_IN_PARTY,
148         CONF_SOUND_PLACE_IN_CONF,
149         CONF_SOUND_WAIT_FOR_LEADER,
150         CONF_SOUND_LEADER_HAS_LEFT,
151         CONF_SOUND_GET_PIN,
152         CONF_SOUND_INVALID_PIN,
153         CONF_SOUND_ONLY_PERSON,
154         CONF_SOUND_LOCKED,
155         CONF_SOUND_LOCKED_NOW,
156         CONF_SOUND_UNLOCKED_NOW,
157         CONF_SOUND_ERROR_MENU,
158         CONF_SOUND_JOIN,
159         CONF_SOUND_LEAVE,
160         CONF_SOUND_PARTICIPANTS_MUTED,
161         CONF_SOUND_PARTICIPANTS_UNMUTED,
162 };
163
164 struct bridge_profile_sounds {
165         AST_DECLARE_STRING_FIELDS(
166                 AST_STRING_FIELD(hasjoin);
167                 AST_STRING_FIELD(hasleft);
168                 AST_STRING_FIELD(kicked);
169                 AST_STRING_FIELD(muted);
170                 AST_STRING_FIELD(unmuted);
171                 AST_STRING_FIELD(onlyone);
172                 AST_STRING_FIELD(thereare);
173                 AST_STRING_FIELD(otherinparty);
174                 AST_STRING_FIELD(placeintoconf);
175                 AST_STRING_FIELD(waitforleader);
176                 AST_STRING_FIELD(leaderhasleft);
177                 AST_STRING_FIELD(getpin);
178                 AST_STRING_FIELD(invalidpin);
179                 AST_STRING_FIELD(onlyperson);
180                 AST_STRING_FIELD(locked);
181                 AST_STRING_FIELD(lockednow);
182                 AST_STRING_FIELD(unlockednow);
183                 AST_STRING_FIELD(errormenu);
184                 AST_STRING_FIELD(leave);
185                 AST_STRING_FIELD(join);
186                 AST_STRING_FIELD(participantsmuted);
187                 AST_STRING_FIELD(participantsunmuted);
188         );
189 };
190
191 struct bridge_profile {
192         char name[64];
193         char rec_file[PATH_MAX];
194         unsigned int flags;
195         unsigned int max_members;          /*!< The maximum number of participants allowed in the conference */
196         unsigned int internal_sample_rate; /*!< The internal sample rate of the bridge. 0 when set to auto adjust mode. */
197         unsigned int mix_interval;  /*!< The internal mixing interval used by the bridge. When set to 0 the bridgewill use a default interval. */
198         struct bridge_profile_sounds *sounds;
199 };
200
201 /*! \brief The structure that represents a conference bridge */
202 struct conference_bridge {
203         char name[MAX_CONF_NAME];                                         /*!< Name of the conference bridge */
204         struct ast_bridge *bridge;                                        /*!< Bridge structure doing the mixing */
205         struct bridge_profile b_profile;                                  /*!< The Bridge Configuration Profile */
206         unsigned int users;                                               /*!< Number of users present */
207         unsigned int markedusers;                                         /*!< Number of marked users present */
208         unsigned int locked:1;                                            /*!< Is this conference bridge locked? */
209         unsigned int muted:1;                                            /*!< Is this conference bridge muted? */
210         struct ast_channel *playback_chan;                                /*!< Channel used for playback into the conference bridge */
211         struct ast_channel *record_chan;                                  /*!< Channel used for recording the conference */
212         pthread_t record_thread;                                          /*!< The thread the recording chan lives in */
213         ast_mutex_t playback_lock;                                        /*!< Lock used for playback channel */
214         AST_LIST_HEAD_NOLOCK(, conference_bridge_user) users_list;        /*!< List of users participating in the conference bridge */
215 };
216
217 /*! \brief The structure that represents a conference bridge user */
218 struct conference_bridge_user {
219         struct conference_bridge *conference_bridge; /*!< Conference bridge they are participating in */
220         struct bridge_profile b_profile;             /*!< The Bridge Configuration Profile */
221         struct user_profile u_profile;               /*!< The User Configuration Profile */
222         char menu_name[64];                          /*!< The name of the DTMF menu assigned to this user */
223         char name_rec_location[PATH_MAX];            /*!< Location of the User's name recorded file if it exists */
224         struct ast_channel *chan;                    /*!< Asterisk channel participating */
225         struct ast_bridge_features features;         /*!< Bridge features structure */
226         struct ast_bridge_tech_optimizations tech_args; /*!< Bridge technology optimizations for talk detection */
227         unsigned int kicked:1;                       /*!< User has been kicked from the conference */
228         unsigned int playing_moh:1;                  /*!< MOH is currently being played to the user */
229         AST_LIST_ENTRY(conference_bridge_user) list; /*!< Linked list information */
230 };
231
232 /*! \brief load confbridge.conf file */
233 int conf_load_config(int reload);
234
235 /*! \brief destroy the information loaded from the confbridge.conf file*/
236 void conf_destroy_config(void);
237
238 /*!
239  * \brief find a user profile given a user profile's name and store
240  * that profile in result structure.
241  *
242  * \details This function first attempts to find any custom user
243  * profile that might exist on a channel datastore, if that doesn't
244  * exist it looks up the provided user profile name, if that doesn't
245  * exist either the default_user profile is used.
246
247  * \retval user profile on success
248  * \retval NULL on failure
249  */
250 const struct user_profile *conf_find_user_profile(struct ast_channel *chan, const char *user_profile_name, struct user_profile *result);
251
252 /*!
253  * \brief Find a bridge profile
254  *
255  * \details Any bridge profile found using this function must be
256  * destroyed using conf_bridge_profile_destroy.  This function first
257  * attempts to find any custom bridge profile that might exist on
258  * a channel datastore, if that doesn't exist it looks up the
259  * provided bridge profile name, if that doesn't exist either
260  * the default_bridge profile is used.
261  *
262  * \retval Bridge profile on success
263  * \retval NULL on failure
264  */
265 const struct bridge_profile *conf_find_bridge_profile(struct ast_channel *chan, const char *bridge_profile_name, struct bridge_profile *result);
266
267 /*!
268  * \brief Destroy a bridge profile found by 'conf_find_bridge_profile'
269  */
270 void conf_bridge_profile_destroy(struct bridge_profile *b_profile);
271
272 /*!
273  * \brief copies a bridge profile
274  * \note conf_bridge_profile_destroy must be called on the dst structure
275  */
276 void conf_bridge_profile_copy(struct bridge_profile *dst, struct bridge_profile *src);
277
278 /*!
279  * \brief Set a DTMF menu to a conference user by menu name.
280  *
281  * \retval 0 on success, menu was found and set
282  * \retval -1 on error, menu was not found
283  */
284 int conf_set_menu_to_user(const char *menu_name, struct conference_bridge_user *conference_bridge_user);
285
286 /*!
287  * \brief Finds a menu_entry in a menu structure matched by DTMF sequence.
288  *
289  * \note the menu entry found must be destroyed using conf_menu_entry_destroy()
290  *
291  * \retval 1 success, entry is found and stored in result
292  * \retval 0 failure, no entry found for given DTMF sequence
293  */
294 int conf_find_menu_entry_by_sequence(const char *dtmf_sequence, struct conf_menu *menu, struct conf_menu_entry *result);
295
296 /*!
297  * \brief Destroys and frees all the actions stored in a menu_entry structure
298  */
299 void conf_menu_entry_destroy(struct conf_menu_entry *menu_entry);
300
301 /*!
302  * \brief Once a DTMF sequence matches a sequence in the user's DTMF menu, this function will get
303  * called to perform the menu action.
304  *
305  * \param bridge_channel, Bridged channel this is involving
306  * \param conference_bridge_user, the conference user to perform the action on.
307  * \param menu_entry, the menu entry that invoked this callback to occur.
308  * \param menu, an AO2 referenced pointer to the entire menu structure the menu_entry
309  *        derived from.
310  *
311  * \note The menu_entry is a deep copy of the entry found in the menu structure.  This allows
312  * for the menu_entry to be accessed without requiring the menu lock.  If the menu must
313  * be accessed, the menu lock must be held.  Reference counting of the menu structure is
314  * handled outside of the scope of this function.
315  *
316  * \retval 0 success
317  * \retval -1 failure
318  */
319 int conf_handle_dtmf(
320         struct ast_bridge_channel *bridge_channel,
321         struct conference_bridge_user *conference_bridge_user,
322         struct conf_menu_entry *menu_entry,
323         struct conf_menu *menu);
324
325
326 /*! \brief Looks to see if sound file is stored in bridge profile sounds, if not
327  *  default sound is provided.*/
328 const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds *custom_sounds);
329
330 int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value);
331 #endif