[svn-commits] file: branch file/bridging r107004 - in /team/file/bridging: apps/ channels/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Sat Mar 8 15:38:49 CST 2008
Author: file
Date: Sat Mar 8 15:38:49 2008
New Revision: 107004
URL: http://svn.digium.com/view/asterisk?view=rev&rev=107004
Log:
Add a basic channel driver which interacts with a bridge. This can be used for playing audio into one or for recording it at the bridge level.
Added:
team/file/bridging/channels/chan_bridge.c (with props)
Modified:
team/file/bridging/apps/app_confbridge.c
Modified: team/file/bridging/apps/app_confbridge.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_confbridge.c?view=diff&rev=107004&r1=107003&r2=107004
==============================================================================
--- team/file/bridging/apps/app_confbridge.c (original)
+++ team/file/bridging/apps/app_confbridge.c Sat Mar 8 15:38:49 2008
@@ -294,6 +294,39 @@
return res;
}
+static void test_bridge_tech(struct ast_bridge *bridge, struct ast_channel *chan, const char *filename)
+{
+ int cause;
+ struct ast_channel *bridge_chan = NULL;
+
+ /* Try to get a Bridge channel to the bridge being used for this conference bridge */
+ if (!(bridge_chan = ast_request("Bridge", chan->nativeformats, "", &cause))) {
+ ast_log(LOG_NOTICE, "Failed to request channel.\n");
+ return;
+ }
+
+ /* Now that we have the channel we have to say what bridge they should become part of */
+ bridge_chan->bridge = bridge;
+
+ /* Now that that is done... actually connect them to it */
+ if (ast_call(bridge_chan, "", 0)) {
+ ast_hangup(bridge_chan);
+ ast_log(LOG_NOTICE, "Oh dear, we screwed up\n");
+ return;
+ }
+
+ /* Huh it worked... */
+ ast_autoservice_start(chan);
+
+ ast_streamfile(bridge_chan, filename, bridge_chan->language);
+ ast_waitstream(bridge_chan, "");
+
+ ast_hangup(bridge_chan);
+
+ ast_autoservice_stop(chan);
+
+ return;
+}
/*! \brief The ConfBridge application */
static int app_exec(struct ast_channel *chan, void *data)
{
@@ -336,6 +369,8 @@
ast_bridge_features_hook(&features, "#", menu_callback, &conference_bridge_user);
}
+ test_bridge_tech(conference_bridge->bridge, chan, "tt-monkeys");
+
/* Join our conference bridge for real */
ast_bridge_join(conference_bridge->bridge, chan, NULL, &features);
Added: team/file/bridging/channels/chan_bridge.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/channels/chan_bridge.c?view=auto&rev=107004
==============================================================================
--- team/file/bridging/channels/chan_bridge.c (added)
+++ team/file/bridging/channels/chan_bridge.c Sat Mar 8 15:38:49 2008
@@ -1,0 +1,199 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2008, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at 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
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ *
+ * \brief Bridge Interaction Channel
+ *
+ * \ingroup channel_drivers
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <fcntl.h>
+#include <sys/signal.h>
+
+#include "asterisk/lock.h"
+#include "asterisk/channel.h"
+#include "asterisk/config.h"
+#include "asterisk/module.h"
+#include "asterisk/pbx.h"
+#include "asterisk/sched.h"
+#include "asterisk/io.h"
+#include "asterisk/rtp.h"
+#include "asterisk/acl.h"
+#include "asterisk/callerid.h"
+#include "asterisk/file.h"
+#include "asterisk/cli.h"
+#include "asterisk/app.h"
+#include "asterisk/bridging.h"
+
+static struct ast_channel *bridge_request(const char *type, int format, void *data, int *cause);
+static int bridge_call(struct ast_channel *ast, char *dest, int timeout);
+static int bridge_hangup(struct ast_channel *ast);
+static struct ast_frame *bridge_read(struct ast_channel *ast);
+static int bridge_write(struct ast_channel *ast, struct ast_frame *f);
+
+static const struct ast_channel_tech bridge_tech = {
+ .type = "Bridge",
+ .description = "Bridge Interaction Channel",
+ .capabilities = -1,
+ .requester = bridge_request,
+ .call = bridge_call,
+ .hangup = bridge_hangup,
+ .read = bridge_read,
+ .write = bridge_write,
+ .write_video = bridge_write,
+ .exception = bridge_read,
+};
+
+struct bridge_pvt {
+ ast_mutex_t lock; /*!< Lock that protects this structure */
+ struct ast_channel *input; /*!< Input channel - talking to source */
+ struct ast_channel *output; /*!< Output channel - talking to bridge */
+};
+
+/*! \brief Called when a frame should be read from the channel */
+static struct ast_frame *bridge_read(struct ast_channel *ast)
+{
+ return &ast_null_frame;
+}
+
+/*! \brief Called when a frame should be written out to a channel */
+static int bridge_write(struct ast_channel *ast, struct ast_frame *f)
+{
+ struct bridge_pvt *p = ast->tech_pvt;
+
+ /* We basically queue the frame up on the other channel if present */
+ ast_mutex_lock(&p->lock);
+ if (p->input && p->output) {
+ ast_queue_frame((p->input == ast ? p->output : p->input), f);
+ }
+ ast_mutex_unlock(&p->lock);
+
+ return 0;
+}
+
+/*! \brief Called when the channel should actually be dialed */
+static int bridge_call(struct ast_channel *ast, char *dest, int timeout)
+{
+ struct bridge_pvt *p = ast->tech_pvt;
+
+ /* If no bridge has been provided on the input channel, bail out */
+ if (!ast->bridge) {
+ return -1;
+ }
+
+ /* Impart the output channel upon the given bridge of the input channel */
+ ast_bridge_impart(p->input->bridge, p->output, NULL, NULL);
+
+ return 0;
+}
+
+/*! \brief Called when a channel should be hung up */
+static int bridge_hangup(struct ast_channel *ast)
+{
+ struct bridge_pvt *p = ast->tech_pvt;
+
+ ast_mutex_lock(&p->lock);
+
+ /* Figure out which channel this is... and set it to NULL as it has gone, but also queue up a hangup frame. */
+ if (p->input == ast) {
+ p->input = NULL;
+ if (p->output) {
+ ast_queue_hangup(p->output);
+ }
+ } else if (p->output == ast) {
+ p->output = NULL;
+ if (p->input) {
+ ast_queue_hangup(p->input);
+ }
+ }
+
+ /* Deal with the Asterisk portion of it */
+ ast->tech_pvt = NULL;
+
+ ast_mutex_unlock(&p->lock);
+
+ /* If both sides have been terminated free the structure and be done with things */
+ if (!p->input && !p->output) {
+ ast_mutex_destroy(&p->lock);
+ ast_free(p);
+ }
+
+ return 0;
+}
+
+/*! \brief Called when we want to place a call somewhere, but not actually call it... yet */
+static struct ast_channel *bridge_request(const char *type, int format, void *data, int *cause)
+{
+ struct bridge_pvt *p = NULL;
+
+ /* Try to allocate memory for our very minimal pvt structure */
+ if (!(p = ast_calloc(1, sizeof(*p)))) {
+ return NULL;
+ }
+
+ /* Try to grab two Asterisk channels to use as input and output channels */
+ if (!(p->input = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-input", p))) {
+ ast_free(p);
+ return NULL;
+ }
+ if (!(p->output = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-output", p))) {
+ ast_channel_free(p->input);
+ ast_free(p);
+ }
+
+ /* Setup the lock on the pvt structure, we will need that */
+ ast_mutex_init(&p->lock);
+
+ /* Setup parameters on both new channels */
+ p->input->tech = p->output->tech = &bridge_tech;
+ p->input->tech_pvt = p->output->tech_pvt = p;
+ p->input->nativeformats = p->output->nativeformats = AST_FORMAT_SLINEAR;
+ p->input->readformat = p->output->readformat = AST_FORMAT_SLINEAR;
+ p->input->rawreadformat = p->output->rawreadformat = AST_FORMAT_SLINEAR;
+ p->input->writeformat = p->output->writeformat = AST_FORMAT_SLINEAR;
+ p->input->rawwriteformat = p->output->rawwriteformat = AST_FORMAT_SLINEAR;
+
+ return p->input;
+}
+
+/*! \brief Load module into PBX, register channel */
+static int load_module(void)
+{
+ /* Make sure we can register our channel type */
+ if (ast_channel_register(&bridge_tech)) {
+ ast_log(LOG_ERROR, "Unable to register channel class 'Bridge'\n");
+ return AST_MODULE_LOAD_FAILURE;
+ }
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+/*! \brief Unload the local proxy channel from Asterisk */
+static int unload_module(void)
+{
+ ast_channel_unregister(&bridge_tech);
+ return 0;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Bridge Interaction Channel");
Propchange: team/file/bridging/channels/chan_bridge.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/file/bridging/channels/chan_bridge.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/file/bridging/channels/chan_bridge.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the svn-commits
mailing list