aboutsummaryrefslogtreecommitdiffstats
path: root/bridges/bridge_simple.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-05 18:18:27 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-05 18:18:27 +0000
commit78d18e52a495a2b1f964a2dceeb7fcc705a79d73 (patch)
treecc242551fdaa17b1537490b8ec0621d2c3fa2c66 /bridges/bridge_simple.c
parent62297fe334460eaa96bc7a2a2c39d9714c77c868 (diff)
Merge phase 1 support for the new bridging architecture.
This commit brings in the bridging core, bridging technologies, and the ConfBridge application. For usage information on the ConfBridge application please see the output of "core show application ConfBridge" from the CLI. For API documentation please see the doxygen page describing the architecture and the documentation for each API call. Review: http://reviewboard.digium.com/r/93/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@180369 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'bridges/bridge_simple.c')
-rw-r--r--bridges/bridge_simple.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/bridges/bridge_simple.c b/bridges/bridge_simple.c
new file mode 100644
index 000000000..0dbcd25d2
--- /dev/null
+++ b/bridges/bridge_simple.c
@@ -0,0 +1,103 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Joshua Colp <jcolp@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.
+ */
+
+/*! \file
+ *
+ * \brief Simple two channel bridging module
+ *
+ * \author Joshua Colp <jcolp@digium.com>
+ *
+ * \ingroup bridges
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/bridging.h"
+#include "asterisk/bridging_technology.h"
+#include "asterisk/frame.h"
+
+static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+ struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan, *c1 = AST_LIST_LAST(&bridge->channels)->chan;
+
+ /* If this is the first channel we can't make it compatible... unless we make it compatible with itself O.o */
+ if (AST_LIST_FIRST(&bridge->channels) == AST_LIST_LAST(&bridge->channels)) {
+ return 0;
+ }
+
+ /* See if we need to make these compatible */
+ if (((c0->writeformat == c1->readformat) && (c0->readformat == c1->writeformat) && (c0->nativeformats == c1->nativeformats))) {
+ return 0;
+ }
+
+ /* BOOM! We do. */
+ return ast_channel_make_compatible(c0, c1);
+}
+
+static enum ast_bridge_write_result simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+{
+ struct ast_bridge_channel *other = NULL;
+
+ /* If this is the only channel in this bridge then immediately exit */
+ if (AST_LIST_FIRST(&bridge->channels) == AST_LIST_LAST(&bridge->channels)) {
+ return AST_BRIDGE_WRITE_FAILED;
+ }
+
+ /* Find the channel we actually want to write to */
+ if (!(other = (AST_LIST_FIRST(&bridge->channels) == bridge_channel ? AST_LIST_LAST(&bridge->channels) : AST_LIST_FIRST(&bridge->channels)))) {
+ return AST_BRIDGE_WRITE_FAILED;
+ }
+
+ /* Write the frame out if they are in the waiting state... don't worry about freeing it, the bridging core will take care of it */
+ if (other->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
+ ast_write(other->chan, frame);
+ }
+
+ return AST_BRIDGE_WRITE_SUCCESS;
+}
+
+static struct ast_bridge_technology simple_bridge = {
+ .name = "simple_bridge",
+ .capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_THREAD,
+ .preference = AST_BRIDGE_PREFERENCE_MEDIUM,
+ .formats = AST_FORMAT_AUDIO_MASK | AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK,
+ .join = simple_bridge_join,
+ .write = simple_bridge_write,
+};
+
+static int unload_module(void)
+{
+ return ast_bridge_technology_unregister(&simple_bridge);
+}
+
+static int load_module(void)
+{
+ return ast_bridge_technology_register(&simple_bridge);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple two channel bridging module");