summaryrefslogtreecommitdiff
path: root/apps/confbridge
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-10-08 18:48:34 +0000
committerMatthew Jordan <mjordan@digium.com>2012-10-08 18:48:34 +0000
commitbe906d63180b25d20e5dfce59658b7f30e56cc99 (patch)
treea3de7fc17f0bd0897093793e2ffa21225d4fc18c /apps/confbridge
parent35b12af8b6aabb91d7dd7ef06e82a3df3d28c520 (diff)
Resolve issues in ConfBridge regarding marked, waitmarked, and unmarked users
Thank's to Neil Tallim (flan)'s tireless testing, issue reporting, and patches it became clear that app_confbridge had some complex logic in how it handled interactions between marked, waitmarked, and unmarked users. In particular, there were some areas in which the interactions between the users resulted in inconsistent behavior, and app_confbridge was missing logic in how to handle some corner cases. Some areas included: * Poor handling of mixing unmarked and waitmarked users * Inconsistencies in how MOH and muting was applied to various users * Handling of various announcements for different user profile options flan's patches seem to fix the various issues, but highlighted how hard the code could be to maintain. In an attempt to make things easier to maintain and to more fully enumerate the various cases that exist, this patch breaks up the logic into a state machine-like setup. Please note that the various state transitioned are documented on the Asterisk wiki: https://wiki.asterisk.org/wiki/display/AST/Confbridge+state+changes Review: //https://reviewboard.asterisk.org/r/2072/ Note that for the following issues, mjordan uploaded the patch, although it was written by twilson. Any contributor license discrepency is due to that. (closes issue ASTERISK-19562) Reported by: flan Tested by: flan, mjordan, jrose patches: bugASTERISK-19562_ASTERISK-19726_ASTERISK-20181.patch uploaded by twilson (license 6283) (closes issue ASTERISK-19726) Reported by: flan Tested by: flan patches: bugASTERISK-19562_ASTERISK-19726_ASTERISK-20181.patch uploaded by twilson (license 6283) (closes issue ASTERISK-20181) Reported by: Jonathan White Tested by: Jonathan White patches: bugASTERISK-19562_ASTERISK-19726_ASTERISK-20181.patch uploaded by twilson (license 6283) ........ Merged revisions 374652 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 374657 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@374658 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps/confbridge')
-rw-r--r--apps/confbridge/conf_state.c70
-rw-r--r--apps/confbridge/conf_state_empty.c86
-rw-r--r--apps/confbridge/conf_state_inactive.c80
-rw-r--r--apps/confbridge/conf_state_multi.c77
-rw-r--r--apps/confbridge/conf_state_multi_marked.c187
-rw-r--r--apps/confbridge/conf_state_single.c84
-rw-r--r--apps/confbridge/conf_state_single_marked.c79
-rw-r--r--apps/confbridge/include/conf_state.h95
-rw-r--r--apps/confbridge/include/confbridge.h116
9 files changed, 872 insertions, 2 deletions
diff --git a/apps/confbridge/conf_state.c b/apps/confbridge/conf_state.c
new file mode 100644
index 000000000..1d8750918
--- /dev/null
+++ b/apps/confbridge/conf_state.c
@@ -0,0 +1,70 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * This file contains functions that are used from multiple conf_state
+ * files for handling stage change behavior.
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include "asterisk/logger.h"
+#include "include/conf_state.h"
+#include "include/confbridge.h"
+
+void conf_invalid_event_fn(struct conference_bridge_user *cbu)
+{
+ ast_log(LOG_ERROR, "Invalid event for confbridge user '%s'\n", cbu->u_profile.name);
+}
+
+void conf_default_join_waitmarked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_waiting(cbu->conference_bridge, cbu);
+ conf_add_post_join_action(cbu, conf_handle_inactive_waitmarked);
+}
+
+void conf_default_leave_waitmarked(struct conference_bridge_user *cbu)
+{
+ conf_remove_user_waiting(cbu->conference_bridge, cbu);
+}
+
+void conf_change_state(struct conference_bridge_user *cbu, struct conference_state *newstate)
+{
+ ast_debug(1, "Changing conference '%s' state from %s to %s\n", cbu->conference_bridge->name, cbu->conference_bridge->state->name, newstate->name);
+ if (cbu->conference_bridge->state->exit) {
+ cbu->conference_bridge->state->exit(cbu);
+ }
+ cbu->conference_bridge->state = newstate;
+ if (cbu->conference_bridge->state->entry) {
+ cbu->conference_bridge->state->entry(cbu);
+ }
+}
diff --git a/apps/confbridge/conf_state_empty.c b/apps/confbridge/conf_state_empty.c
new file mode 100644
index 000000000..22997ad2c
--- /dev/null
+++ b/apps/confbridge/conf_state_empty.c
@@ -0,0 +1,86 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling for the EMPTY state
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+#include "asterisk/devicestate.h"
+#include "include/confbridge.h"
+#include "include/conf_state.h"
+
+static void join_unmarked(struct conference_bridge_user *cbu);
+static void join_waitmarked(struct conference_bridge_user *cbu);
+static void join_marked(struct conference_bridge_user *cbu);
+static void transition_to_empty(struct conference_bridge_user *cbu);
+
+struct conference_state STATE_EMPTY = {
+ .name = "EMPTY",
+ .join_unmarked = join_unmarked,
+ .join_waitmarked = join_waitmarked,
+ .join_marked = join_marked,
+ .entry = transition_to_empty,
+};
+
+struct conference_state *CONF_STATE_EMPTY = &STATE_EMPTY;
+
+static void join_unmarked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_active(cbu->conference_bridge, cbu);
+ conf_handle_first_join(cbu->conference_bridge);
+ conf_add_post_join_action(cbu, conf_handle_only_unmarked);
+
+ conf_change_state(cbu, CONF_STATE_SINGLE);
+}
+
+static void join_waitmarked(struct conference_bridge_user *cbu)
+{
+ conf_default_join_waitmarked(cbu);
+ conf_handle_first_join(cbu->conference_bridge);
+
+ conf_change_state(cbu, CONF_STATE_INACTIVE);
+}
+
+static void join_marked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_marked(cbu->conference_bridge, cbu);
+ conf_handle_first_join(cbu->conference_bridge);
+ conf_add_post_join_action(cbu, conf_handle_first_marked_common);
+
+ conf_change_state(cbu, CONF_STATE_SINGLE_MARKED);
+}
+
+static void transition_to_empty(struct conference_bridge_user *cbu)
+{
+ /* Set device state to "not in use" */
+ ast_devstate_changed(AST_DEVICE_NOT_INUSE, "confbridge:%s", cbu->conference_bridge->name);
+ conf_ended(cbu->conference_bridge);
+}
diff --git a/apps/confbridge/conf_state_inactive.c b/apps/confbridge/conf_state_inactive.c
new file mode 100644
index 000000000..80210fcb8
--- /dev/null
+++ b/apps/confbridge/conf_state_inactive.c
@@ -0,0 +1,80 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling for the INACTIVE state
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "include/confbridge.h"
+#include "include/conf_state.h"
+
+static void join_unmarked(struct conference_bridge_user *cbu);
+static void join_marked(struct conference_bridge_user *cbu);
+static void leave_waitmarked(struct conference_bridge_user *cbu);
+static void transition_to_inactive(struct conference_bridge_user *cbu);
+
+struct conference_state STATE_INACTIVE = {
+ .name = "INACTIVE",
+ .join_unmarked = join_unmarked,
+ .join_waitmarked = conf_default_join_waitmarked,
+ .join_marked = join_marked,
+ .leave_waitmarked = leave_waitmarked,
+ .entry = transition_to_inactive,
+};
+struct conference_state *CONF_STATE_INACTIVE = &STATE_INACTIVE;
+
+static void join_unmarked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_active(cbu->conference_bridge, cbu);
+ conf_add_post_join_action(cbu, conf_handle_only_unmarked);
+
+ conf_change_state(cbu, CONF_STATE_SINGLE);
+}
+
+static void join_marked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_marked(cbu->conference_bridge, cbu);
+ conf_handle_second_active(cbu->conference_bridge);
+
+ conf_change_state(cbu, CONF_STATE_MULTI_MARKED);
+}
+
+static void leave_waitmarked(struct conference_bridge_user *cbu)
+{
+ conf_remove_user_waiting(cbu->conference_bridge, cbu);
+ if (cbu->conference_bridge->waitingusers == 0) {
+ conf_change_state(cbu, CONF_STATE_EMPTY);
+ }
+}
+
+static void transition_to_inactive(struct conference_bridge_user *cbu)
+{
+ return;
+}
diff --git a/apps/confbridge/conf_state_multi.c b/apps/confbridge/conf_state_multi.c
new file mode 100644
index 000000000..5dcd8f412
--- /dev/null
+++ b/apps/confbridge/conf_state_multi.c
@@ -0,0 +1,77 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling for the MULTI state
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "include/confbridge.h"
+#include "include/conf_state.h"
+
+static void join_unmarked(struct conference_bridge_user *cbu);
+static void join_marked(struct conference_bridge_user *cbu);
+static void leave_unmarked(struct conference_bridge_user *cbu);
+void transition_to_multi(struct conference_bridge_user *cbu);
+
+struct conference_state STATE_MULTI = {
+ .name = "MULTI",
+ .join_unmarked = join_unmarked,
+ .join_waitmarked = conf_default_join_waitmarked,
+ .join_marked = join_marked,
+ .leave_unmarked = leave_unmarked,
+ .leave_waitmarked = conf_default_leave_waitmarked,
+ .entry = transition_to_multi,
+};
+struct conference_state *CONF_STATE_MULTI = &STATE_MULTI;
+
+static void join_unmarked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_active(cbu->conference_bridge, cbu);
+}
+
+static void join_marked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_marked(cbu->conference_bridge, cbu);
+
+ conf_change_state(cbu, CONF_STATE_MULTI_MARKED);
+}
+
+static void leave_unmarked(struct conference_bridge_user *cbu)
+{
+ conf_remove_user_active(cbu->conference_bridge, cbu);
+ if (cbu->conference_bridge->activeusers == 1) {
+ conf_change_state(cbu, CONF_STATE_SINGLE);
+ }
+}
+
+void transition_to_multi(struct conference_bridge_user *cbu)
+{
+ return;
+}
diff --git a/apps/confbridge/conf_state_multi_marked.c b/apps/confbridge/conf_state_multi_marked.c
new file mode 100644
index 000000000..69850b18d
--- /dev/null
+++ b/apps/confbridge/conf_state_multi_marked.c
@@ -0,0 +1,187 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling for the MULTI_MARKED state
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+#include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
+#include "include/confbridge.h"
+#include "asterisk/musiconhold.h"
+#include "include/conf_state.h"
+
+static void join_active(struct conference_bridge_user *cbu);
+static void join_marked(struct conference_bridge_user *cbu);
+static void leave_active(struct conference_bridge_user *cbu);
+static void leave_marked(struct conference_bridge_user *cbu);
+static void transition_to_marked(struct conference_bridge_user *cbu);
+
+static struct conference_state STATE_MULTI_MARKED = {
+ .name = "MULTI_MARKED",
+ .join_unmarked = join_active,
+ .join_waitmarked = join_active,
+ .join_marked = join_marked,
+ .leave_unmarked = leave_active,
+ .leave_waitmarked = leave_active,
+ .leave_marked = leave_marked,
+ .entry = transition_to_marked,
+};
+struct conference_state *CONF_STATE_MULTI_MARKED = &STATE_MULTI_MARKED;
+
+static void join_active(struct conference_bridge_user *cbu)
+{
+ conf_add_user_active(cbu->conference_bridge, cbu);
+}
+
+static void join_marked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_marked(cbu->conference_bridge, cbu);
+}
+
+static void leave_active(struct conference_bridge_user *cbu)
+{
+ conf_remove_user_active(cbu->conference_bridge, cbu);
+ if (cbu->conference_bridge->activeusers == 1) {
+ conf_change_state(cbu, CONF_STATE_SINGLE_MARKED);
+ }
+}
+
+static void leave_marked(struct conference_bridge_user *cbu)
+{
+ struct conference_bridge_user *cbu_iter;
+
+ conf_remove_user_marked(cbu->conference_bridge, cbu);
+
+ if (cbu->conference_bridge->markedusers == 0) {
+ /* Play back the audio prompt saying the leader has left the conference */
+ if (!ast_test_flag(&cbu->u_profile, USER_OPT_QUIET)) {
+ ao2_unlock(cbu->conference_bridge);
+ ast_autoservice_start(cbu->chan);
+ play_sound_file(cbu->conference_bridge,
+ conf_get_sound(CONF_SOUND_LEADER_HAS_LEFT, cbu->b_profile.sounds));
+ ast_autoservice_stop(cbu->chan);
+ ao2_lock(cbu->conference_bridge);
+ }
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&cbu->conference_bridge->active_list, cbu_iter, list) {
+ /* Kick ENDMARKED cbu_iters */
+ if (ast_test_flag(&cbu_iter->u_profile, USER_OPT_ENDMARKED)) {
+ AST_LIST_REMOVE_CURRENT(list);
+ cbu_iter->conference_bridge->activeusers--;
+ cbu_iter->kicked = 1;
+ ast_bridge_remove(cbu_iter->conference_bridge->bridge, cbu_iter->chan);
+ } else if (ast_test_flag(&cbu_iter->u_profile, USER_OPT_WAITMARKED) &&
+ !ast_test_flag(&cbu_iter->u_profile, USER_OPT_MARKEDUSER)) {
+ AST_LIST_REMOVE_CURRENT(list);
+ cbu_iter->conference_bridge->activeusers--;
+ AST_LIST_INSERT_TAIL(&cbu_iter->conference_bridge->waiting_list, cbu_iter, list);
+ cbu_iter->conference_bridge->waitingusers++;
+ /* Handle muting/moh of cbu_iter if necessary */
+ if (ast_test_flag(&cbu_iter->u_profile, USER_OPT_MUSICONHOLD)) {
+ cbu_iter->features.mute = 1;
+ if (!ast_bridge_suspend(cbu_iter->conference_bridge->bridge, cbu_iter->chan)) {
+ ast_moh_start(cbu_iter->chan, cbu_iter->u_profile.moh_class, NULL);
+ cbu_iter->playing_moh = 1;
+ ast_bridge_unsuspend(cbu_iter->conference_bridge->bridge, cbu_iter->chan);
+ }
+ }
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ }
+
+ switch (cbu->conference_bridge->activeusers) {
+ case 0:
+ /* Implies markedusers == 0 */
+ switch (cbu->conference_bridge->waitingusers) {
+ case 0:
+ conf_change_state(cbu, CONF_STATE_EMPTY);
+ break;
+ default:
+ conf_change_state(cbu, CONF_STATE_INACTIVE);
+ break;
+ }
+ break;
+ case 1:
+ switch (cbu->conference_bridge->markedusers) {
+ case 0:
+ conf_change_state(cbu, CONF_STATE_SINGLE);
+ break;
+ case 1:
+ /* XXX I seem to remember doing this for a reason, but right now it escapes me
+ * how we could possibly ever have a waiting user while we have a marked user */
+ switch (cbu->conference_bridge->waitingusers) {
+ case 0:
+ conf_change_state(cbu, CONF_STATE_SINGLE_MARKED);
+ break;
+ case 1: break; /* Stay in marked */
+ }
+ break;
+ }
+ break;
+ default:
+ switch (cbu->conference_bridge->markedusers) {
+ case 0:
+ conf_change_state(cbu, CONF_STATE_MULTI);
+ break;
+ default: break; /* Stay in marked */
+ }
+ }
+}
+
+static void transition_to_marked(struct conference_bridge_user *cbu)
+{
+ struct conference_bridge_user *cbu_iter;
+
+ /* Play the audio file stating they are going to be placed into the conference */
+ if (cbu->conference_bridge->markedusers == 1 && ast_test_flag(&cbu->u_profile, USER_OPT_MARKEDUSER)) {
+ conf_handle_first_marked_common(cbu);
+ }
+
+ /* Move all waiting users to active, stopping MOH and umuting if necessary */
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&cbu->conference_bridge->waiting_list, cbu_iter, list) {
+ AST_LIST_REMOVE_CURRENT(list);
+ cbu->conference_bridge->waitingusers--;
+ AST_LIST_INSERT_TAIL(&cbu->conference_bridge->active_list, cbu_iter, list);
+ cbu->conference_bridge->activeusers++;
+ if (cbu_iter->playing_moh && !ast_bridge_suspend(cbu->conference_bridge->bridge, cbu_iter->chan)) {
+ cbu_iter->playing_moh = 0;
+ ast_moh_stop(cbu_iter->chan);
+ ast_bridge_unsuspend(cbu->conference_bridge->bridge, cbu_iter->chan);
+ }
+ /* only unmute them if they are not supposed to start muted */
+ if (!ast_test_flag(&cbu_iter->u_profile, USER_OPT_STARTMUTED)) {
+ cbu_iter->features.mute = 0;
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+}
diff --git a/apps/confbridge/conf_state_single.c b/apps/confbridge/conf_state_single.c
new file mode 100644
index 000000000..806ed637b
--- /dev/null
+++ b/apps/confbridge/conf_state_single.c
@@ -0,0 +1,84 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling for the SINGLE state
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "include/confbridge.h"
+#include "include/conf_state.h"
+
+static void join_unmarked(struct conference_bridge_user *cbu);
+static void join_marked(struct conference_bridge_user *cbu);
+static void leave_unmarked(struct conference_bridge_user *cbu);
+static void transition_to_single(struct conference_bridge_user *cbu);
+
+struct conference_state STATE_SINGLE = {
+ .name = "SINGLE",
+ .join_unmarked = join_unmarked,
+ .join_waitmarked = conf_default_join_waitmarked,
+ .join_marked = join_marked,
+ .leave_unmarked = leave_unmarked,
+ .leave_waitmarked = conf_default_leave_waitmarked,
+ .entry = transition_to_single,
+};
+struct conference_state *CONF_STATE_SINGLE = &STATE_SINGLE;
+
+static void join_unmarked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_active(cbu->conference_bridge, cbu);
+ conf_handle_second_active(cbu->conference_bridge);
+
+ conf_change_state(cbu, CONF_STATE_MULTI);
+}
+
+static void join_marked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_marked(cbu->conference_bridge, cbu);
+ conf_handle_second_active(cbu->conference_bridge);
+
+ conf_change_state(cbu, CONF_STATE_MULTI_MARKED);
+}
+
+static void leave_unmarked(struct conference_bridge_user *cbu)
+{
+ conf_remove_user_active(cbu->conference_bridge, cbu);
+
+ if (cbu->conference_bridge->waitingusers) {
+ conf_change_state(cbu, CONF_STATE_INACTIVE);
+ } else {
+ conf_change_state(cbu, CONF_STATE_EMPTY);
+ }
+}
+
+static void transition_to_single(struct conference_bridge_user *cbu)
+{
+ conf_mute_only_active(cbu->conference_bridge);
+}
diff --git a/apps/confbridge/conf_state_single_marked.c b/apps/confbridge/conf_state_single_marked.c
new file mode 100644
index 000000000..a7ac57816
--- /dev/null
+++ b/apps/confbridge/conf_state_single_marked.c
@@ -0,0 +1,79 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling for the SINGLE_MARKED state
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "include/confbridge.h"
+#include "include/conf_state.h"
+
+static void join_active(struct conference_bridge_user *cbu);
+static void join_marked(struct conference_bridge_user *cbu);
+static void leave_marked(struct conference_bridge_user *cbu);
+static void transition_to_single_marked(struct conference_bridge_user *cbu);
+
+struct conference_state STATE_SINGLE_MARKED = {
+ .name = "SINGLE_MARKED",
+ .join_unmarked = join_active,
+ .join_waitmarked = join_active,
+ .join_marked = join_marked,
+ .leave_marked = leave_marked,
+ .entry = transition_to_single_marked,
+};
+struct conference_state *CONF_STATE_SINGLE_MARKED = &STATE_SINGLE_MARKED;
+
+static void join_active(struct conference_bridge_user *cbu)
+{
+ conf_add_user_active(cbu->conference_bridge, cbu);
+ conf_handle_second_active(cbu->conference_bridge);
+
+ conf_change_state(cbu, CONF_STATE_MULTI_MARKED);
+}
+
+static void join_marked(struct conference_bridge_user *cbu)
+{
+ conf_add_user_marked(cbu->conference_bridge, cbu);
+ conf_handle_second_active(cbu->conference_bridge);
+
+ conf_change_state(cbu, CONF_STATE_MULTI_MARKED);
+}
+
+static void leave_marked(struct conference_bridge_user *cbu)
+{
+ conf_remove_user_marked(cbu->conference_bridge, cbu);
+
+ conf_change_state(cbu, CONF_STATE_EMPTY);
+}
+
+static void transition_to_single_marked(struct conference_bridge_user *cbu)
+{
+ conf_mute_only_active(cbu->conference_bridge);
+}
diff --git a/apps/confbridge/include/conf_state.h b/apps/confbridge/include/conf_state.h
new file mode 100644
index 000000000..8a2585095
--- /dev/null
+++ b/apps/confbridge/include/conf_state.h
@@ -0,0 +1,95 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Terry Wilson
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ *
+ * Please follow coding guidelines
+ * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
+ */
+
+/*! \file
+ *
+ * \brief Confbridge state handling
+ *
+ * \author\verbatim Terry Wilson <twilson@digium.com> \endverbatim
+ *
+ * See https://wiki.asterisk.org/wiki/display/AST/Confbridge+state+changes for
+ * a more complete description of how conference states work.
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#ifndef _CONF_STATE_H_
+#define _CONF_STATE_H_
+
+struct conference_state;
+struct conference_bridge;
+struct conference_bridge_user;
+
+typedef void (*conference_event_fn)(struct conference_bridge_user *cbu);
+typedef void (*conference_entry_fn)(struct conference_bridge_user *cbu);
+typedef void (*conference_exit_fn)(struct conference_bridge_user *cbu);
+
+/*! \brief A conference state object to hold the various state callback functions */
+struct conference_state {
+ const char *name;
+ conference_event_fn join_unmarked; /*!< Handle an unmarked join event */
+ conference_event_fn join_waitmarked; /*!< Handle a waitmarked join event */
+ conference_event_fn join_marked; /*!< Handle a marked join event */
+ conference_event_fn leave_unmarked; /*!< Handle an unmarked leave event */
+ conference_event_fn leave_waitmarked; /*!< Handle a waitmarked leave event */
+ conference_event_fn leave_marked; /*!< Handle a marked leave event */
+ conference_entry_fn entry; /*!< Function to handle entry to a state */
+ conference_exit_fn exit; /*!< Function to handle exiting from a state */
+};
+
+/*! \brief Conference state with no active or waiting users */
+extern struct conference_state *CONF_STATE_EMPTY;
+
+/*! \brief Conference state with only waiting users */
+extern struct conference_state *CONF_STATE_INACTIVE;
+
+/*! \brief Conference state with only a single unmarked active user */
+extern struct conference_state *CONF_STATE_SINGLE;
+
+/*! \brief Conference state with only a single marked active user */
+extern struct conference_state *CONF_STATE_SINGLE_MARKED;
+
+/*! \brief Conference state with multiple active users, but no marked users */
+extern struct conference_state *CONF_STATE_MULTI;
+
+/*! \brief Conference state with multiple active users and at least one marked user */
+extern struct conference_state *CONF_STATE_MULTI_MARKED;
+
+/*! \brief Execute conference state transition because of a user action
+ * \param cbu The user that joined/left
+ * \param newstate The state to transition to
+ */
+void conf_change_state(struct conference_bridge_user *cbu, struct conference_state *newstate);
+
+/* Common event handlers shared between different states */
+
+/*! \brief Logic to execute every time a waitmarked user joins an unmarked conference */
+void conf_default_join_waitmarked(struct conference_bridge_user *cbu);
+
+/*! \brief Logic to execute every time a waitmarked user leaves an unmarked conference */
+void conf_default_leave_waitmarked(struct conference_bridge_user *cbu);
+
+/*! \brief A handler for join/leave events that are invalid in a particular state */
+void conf_invalid_event_fn(struct conference_bridge_user *cbu);
+
+#endif
diff --git a/apps/confbridge/include/confbridge.h b/apps/confbridge/include/confbridge.h
index 54a9af329..0891f5d4e 100644
--- a/apps/confbridge/include/confbridge.h
+++ b/apps/confbridge/include/confbridge.h
@@ -28,6 +28,7 @@
#include "asterisk/channel.h"
#include "asterisk/bridging.h"
#include "asterisk/bridging_features.h"
+#include "conf_state.h"
/* Maximum length of a conference bridge name */
#define MAX_CONF_NAME 32
@@ -201,17 +202,28 @@ struct bridge_profile {
/*! \brief The structure that represents a conference bridge */
struct conference_bridge {
char name[MAX_CONF_NAME]; /*!< Name of the conference bridge */
+ struct conference_state *state; /*!< Conference state information */
struct ast_bridge *bridge; /*!< Bridge structure doing the mixing */
struct bridge_profile b_profile; /*!< The Bridge Configuration Profile */
- unsigned int users; /*!< Number of users present */
+ unsigned int activeusers; /*!< Number of active users present */
unsigned int markedusers; /*!< Number of marked users present */
+ unsigned int waitingusers; /*!< Number of waiting users present */
unsigned int locked:1; /*!< Is this conference bridge locked? */
unsigned int muted:1; /*!< Is this conference bridge muted? */
+ unsigned int record_state:2; /*!< Whether recording is started, stopped, or should exit */
struct ast_channel *playback_chan; /*!< Channel used for playback into the conference bridge */
struct ast_channel *record_chan; /*!< Channel used for recording the conference */
pthread_t record_thread; /*!< The thread the recording chan lives in */
ast_mutex_t playback_lock; /*!< Lock used for playback channel */
- AST_LIST_HEAD_NOLOCK(, conference_bridge_user) users_list; /*!< List of users participating in the conference bridge */
+ ast_mutex_t record_lock; /*!< Lock used for the record thread */
+ ast_cond_t record_cond; /*!< Recording condition variable */
+ AST_LIST_HEAD_NOLOCK(, conference_bridge_user) active_list; /*!< List of users participating in the conference bridge */
+ AST_LIST_HEAD_NOLOCK(, conference_bridge_user) waiting_list; /*!< List of users waiting to join the conference bridge */
+};
+
+struct post_join_action {
+ int (*func)(struct conference_bridge_user *);
+ AST_LIST_ENTRY(post_join_action) list;
};
/*! \brief The structure that represents a conference bridge user */
@@ -226,6 +238,7 @@ struct conference_bridge_user {
struct ast_bridge_tech_optimizations tech_args; /*!< Bridge technology optimizations for talk detection */
unsigned int kicked:1; /*!< User has been kicked from the conference */
unsigned int playing_moh:1; /*!< MOH is currently being played to the user */
+ AST_LIST_HEAD_NOLOCK(, post_join_action) post_join_list; /*!< List of sounds to play after joining */;
AST_LIST_ENTRY(conference_bridge_user) list; /*!< Linked list information */
};
@@ -328,4 +341,103 @@ int conf_handle_dtmf(
const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds *custom_sounds);
int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value);
+
+/*!
+ * \brief Play sound file into conference bridge
+ *
+ * \param conference_bridge The conference bridge to play sound file into
+ * \param filename Sound file to play
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int play_sound_file(struct conference_bridge *conference_bridge, const char *filename);
+
+/*! \brief Callback to be called when the conference has become empty
+ * \param conference_bridge The conference bridge
+ */
+void conf_ended(struct conference_bridge *conference_bridge);
+
+/*! \brief Attempt to mute/play MOH to the only user in the conference if they require it
+ * \param conference_bridge A conference bridge containing a single user
+ */
+void conf_mute_only_active(struct conference_bridge *conference_bridge);
+
+/*! \brief Callback to execute any time we transition from zero to one marked users
+ * \param cbu The first marked user joining the conference
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int conf_handle_first_marked_common(struct conference_bridge_user *cbu);
+
+/*! \brief Callback to execute any time we transition from zero to one active users
+ * \param conference_bridge The conference bridge with a single active user joined
+ * \retval 0 success
+ * \retval -1 failure
+ */
+void conf_handle_first_join(struct conference_bridge *conference_bridge);
+
+/*! \brief Handle actions every time a waitmarked user joins w/o a marked user present
+ * \param cbu The waitmarked user
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int conf_handle_inactive_waitmarked(struct conference_bridge_user *cbu);
+
+/*! \brief Handle actions whenever an unmarked user joins an inactive conference
+ * \note These actions seem like they could apply just as well to a marked user
+ * and possibly be made to happen any time transitioning to a single state.
+ *
+ * \param cbu The unmarked user
+ */
+int conf_handle_only_unmarked(struct conference_bridge_user *cbu);
+
+/*! \brief Handle when a conference moves to having more than one active participant
+ * \param conference_bridge The conference bridge with more than one active participant
+ */
+void conf_handle_second_active(struct conference_bridge *conference_bridge);
+
+/*! \brief Add a conference bridge user as an unmarked active user of the conference
+ * \param conference_bridge The conference bridge to add the user to
+ * \param cbu The conference bridge user to add to the conference
+ */
+void conf_add_user_active(struct conference_bridge *conference_bridge, struct conference_bridge_user *cbu);
+
+/*! \brief Add a conference bridge user as a marked active user of the conference
+ * \param conference_bridge The conference bridge to add the user to
+ * \param cbu The conference bridge user to add to the conference
+ */
+void conf_add_user_marked(struct conference_bridge *conference_bridge, struct conference_bridge_user *cbu);
+
+/*! \brief Add a conference bridge user as an waiting user of the conference
+ * \param conference_bridge The conference bridge to add the user to
+ * \param cbu The conference bridge user to add to the conference
+ */
+void conf_add_user_waiting(struct conference_bridge *conference_bridge, struct conference_bridge_user *cbu);
+
+/*! \brief Remove a conference bridge user from the unmarked active conference users in the conference
+ * \param conference_bridge The conference bridge to remove the user from
+ * \param cbu The conference bridge user to remove from the conference
+ */
+void conf_remove_user_active(struct conference_bridge *conference_bridge, struct conference_bridge_user *cbu);
+
+/*! \brief Remove a conference bridge user from the marked active conference users in the conference
+ * \param conference_bridge The conference bridge to remove the user from
+ * \param cbu The conference bridge user to remove from the conference
+ */
+void conf_remove_user_marked(struct conference_bridge *conference_bridge, struct conference_bridge_user *cbu);
+
+/*! \brief Remove a conference bridge user from the waiting conference users in the conference
+ * \param conference_bridge The conference bridge to remove the user from
+ * \param cbu The conference bridge user to remove from the conference
+ */
+void conf_remove_user_waiting(struct conference_bridge *conference_bridge, struct conference_bridge_user *cbu);
+
+/*! \brief Queue a function to run with the given conference bridge user as an argument once the state transition is complete
+ * \param cbu The conference bridge user to pass to the function
+ * \param func The function to queue
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+int conf_add_post_join_action(struct conference_bridge_user *cbu, int (*func)(struct conference_bridge_user *cbu));
#endif