2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2011, Digium, Inc.
6 * David Vossel <dvossel@digium.com>
7 * Joshua Colp <jcolp@digium.com>
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.
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.
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"
32 /* Maximum length of a conference bridge name */
33 #define MAX_CONF_NAME 32
34 /* Maximum length of a conference pin */
37 #define DEFAULT_USER_PROFILE "default_user"
38 #define DEFAULT_BRIDGE_PROFILE "default_bridge"
40 #define DEFAULT_TALKING_THRESHOLD 160
41 #define DEFAULT_SILENCE_THRESHOLD 2500
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. */
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. */
69 enum conf_menu_action_id {
70 MENU_ACTION_TOGGLE_MUTE = 1,
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,
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,
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;
97 char playback_file[PATH_MAX];
99 char context[AST_MAX_CONTEXT];
100 char exten[AST_MAX_EXTENSION];
104 AST_LIST_ENTRY(conf_menu_action) action;
107 /*! Conference menu entries contain the DTMF sequence
108 * and the list of actions that are associated with that
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;
118 /*! Conference menu structure. Contains a list
119 * of DTMF sequences coupled with the actions those
120 * sequences invoke.*/
124 AST_LIST_HEAD_NOLOCK(, conf_menu_entry) entries;
127 struct user_profile {
131 char announcement[PATH_MAX];
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;
142 CONF_SOUND_HAS_JOINED,
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,
154 CONF_SOUND_INVALID_PIN,
155 CONF_SOUND_ONLY_PERSON,
157 CONF_SOUND_LOCKED_NOW,
158 CONF_SOUND_UNLOCKED_NOW,
159 CONF_SOUND_ERROR_MENU,
162 CONF_SOUND_PARTICIPANTS_MUTED,
163 CONF_SOUND_PARTICIPANTS_UNMUTED,
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);
193 struct bridge_profile {
195 char rec_file[PATH_MAX];
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;
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 */
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 */
235 /*! \brief load confbridge.conf file */
236 int conf_load_config(int reload);
238 /*! \brief destroy the information loaded from the confbridge.conf file*/
239 void conf_destroy_config(void);
242 * \brief find a user profile given a user profile's name and store
243 * that profile in result structure.
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.
250 * \retval user profile on success
251 * \retval NULL on failure
253 const struct user_profile *conf_find_user_profile(struct ast_channel *chan, const char *user_profile_name, struct user_profile *result);
256 * \brief Find a bridge profile
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.
265 * \retval Bridge profile on success
266 * \retval NULL on failure
268 const struct bridge_profile *conf_find_bridge_profile(struct ast_channel *chan, const char *bridge_profile_name, struct bridge_profile *result);
271 * \brief Destroy a bridge profile found by 'conf_find_bridge_profile'
273 void conf_bridge_profile_destroy(struct bridge_profile *b_profile);
276 * \brief copies a bridge profile
277 * \note conf_bridge_profile_destroy must be called on the dst structure
279 void conf_bridge_profile_copy(struct bridge_profile *dst, struct bridge_profile *src);
282 * \brief Set a DTMF menu to a conference user by menu name.
284 * \retval 0 on success, menu was found and set
285 * \retval -1 on error, menu was not found
287 int conf_set_menu_to_user(const char *menu_name, struct conference_bridge_user *conference_bridge_user);
290 * \brief Finds a menu_entry in a menu structure matched by DTMF sequence.
292 * \note the menu entry found must be destroyed using conf_menu_entry_destroy()
294 * \retval 1 success, entry is found and stored in result
295 * \retval 0 failure, no entry found for given DTMF sequence
297 int conf_find_menu_entry_by_sequence(const char *dtmf_sequence, struct conf_menu *menu, struct conf_menu_entry *result);
300 * \brief Destroys and frees all the actions stored in a menu_entry structure
302 void conf_menu_entry_destroy(struct conf_menu_entry *menu_entry);
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.
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
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.
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);
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);
333 int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value);