[svn-commits] file: branch file/bridging r65487 - /team/file/bridging/bridges/bridge_zaptel.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue May 22 09:55:06 MST 2007


Author: file
Date: Tue May 22 11:55:06 2007
New Revision: 65487

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65487
Log:
Add preliminary bridge_zaptel module. Doesn't actually do anything with frames written in yet or handle the signed linear requirement.

Added:
    team/file/bridging/bridges/bridge_zaptel.c   (with props)

Added: team/file/bridging/bridges/bridge_zaptel.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/bridges/bridge_zaptel.c?view=auto&rev=65487
==============================================================================
--- team/file/bridging/bridges/bridge_zaptel.c (added)
+++ team/file/bridging/bridges/bridge_zaptel.c Tue May 22 11:55:06 2007
@@ -1,0 +1,217 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, 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
+ *
+ * \brief Zaptel mixing bridge module
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ *
+ * \ingroup bridges
+ */
+
+/*** MODULEINFO
+        <depend>zaptel</depend>
+***/
+
+#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 <sys/fcntl.h>
+
+#include "asterisk/zapata.h"
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/bridging.h"
+#include "asterisk/frame.h"
+#include "asterisk/lock.h"
+#include "asterisk/linkedlists.h"
+
+struct zaptel_mixer {
+	int fd;   /*!< File descriptor for the pseudo channel */
+	int conf; /*!< Zaptel conference number */
+	AST_LIST_HEAD_NOLOCK(, zaptel_mixer_channel) channels;
+};
+
+struct zaptel_mixer_channel {
+	int fd; /*!< File descriptor for our listening/talking channel */
+	AST_LIST_ENTRY(zaptel_mixer_channel) list;
+};
+
+static int zaptel_bridge_create(struct ast_bridge *bridge)
+{
+	struct zaptel_mixer *zm = NULL;
+	struct zt_confinfo ztc = { 0, };
+
+	/* Create a new zaptel-specific mixer structure */
+	if (!(zm = ast_calloc(1, sizeof(*zm))))
+		return -1;
+
+	/* Create a new zaptel pseudo channel to use for mixing */
+	if ((zm->fd = open("/dev/zap/pseudo", O_RDWR)) < 0) {
+		free(zm);
+		return -1;
+	}
+
+	/* Setup zaptel conference parameters and apply them */
+	ztc.confno = -1;
+	ztc.confmode = ZT_CONF_CONFANN | ZT_CONF_CONFANNMON;
+	if (ioctl(zm->fd, ZT_SETCONF, &zm)) {
+		close(zm->fd);
+		free(zm);
+		return -1;
+	}
+	zm->conf = ztc.confno;
+	
+	/* All parameters are setup and the zaptel mixer is up... link it to the bridge */
+	bridge->bridge_pvt = zm;
+
+	return 0;
+}
+
+static int zaptel_bridge_destroy(struct ast_bridge *bridge)
+{
+	struct zaptel_mixer *zm = bridge->bridge_pvt;
+
+	/* Drop the zaptel conference room */
+	close(zm->fd);
+
+	/* Free our memory and go on our way... */
+	free(zm);
+
+	return 0;
+}
+
+static int zaptel_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+	struct zaptel_mixer *zm = bridge->bridge_pvt;
+	struct zaptel_mixer_channel *zmc = NULL;
+	struct zt_confinfo ztc = { 0, };
+	int flags = 0, x = 1;
+	ZT_BUFFERINFO bi;
+
+	/* Boom! Need another structure */
+	if (!(zmc = ast_calloc(1, sizeof(*zmc))))
+		return -1;
+
+	/* Attempt to open the pseudo channel */
+	if ((zmc->fd = open("/dev/zap/pseudo", O_RDWR)) < 0) {
+		free(zmc);
+		return -1;
+	}
+
+	/* Switch to non-blocking */
+	if (((flags = fcntl(zmc->fd, F_GETFL)) < 0) || (fcntl(zmc->fd, F_SETFL, flags | O_NONBLOCK))) {
+		close(zmc->fd);
+		free(zmc);
+		return -1;
+	}
+
+	/* Setup buffering parameters */
+	memset(&bi, 0, sizeof(bi));
+	bi.bufsize = 160;
+	bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
+	bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
+	bi.numbufs = 32;
+
+	/* Apply the above */
+	if (ioctl(zmc->fd, ZT_SET_BUFINFO, &bi)) {
+		close(zmc->fd);
+		free(zmc);
+		return -1;
+	}
+
+	/* Set linear mode */
+	if (ioctl(zmc->fd, ZT_SETLINEAR, &x)) {
+		close(zmc->fd);
+		free(zmc);
+		return -1;
+	}
+
+	/* Add us to the conference */
+	ztc.confno = zm->conf;
+	ztc.confmode = ZT_CONF_CONF | ZT_CONF_TALKER | ZT_CONF_LISTENER;
+	if (ioctl(zmc->fd, ZT_SETCONF, &ztc)) {
+		close(zmc->fd);
+		free(zmc);
+		return -1;
+	}
+
+	/* Add ourselves to the zaptel mixer structure */
+	AST_LIST_INSERT_TAIL(&zm->channels, zmc, list);
+	
+	/* We "should" be a go */
+	bridge_channel->bridge_pvt = zmc;
+
+	return 0;
+}
+
+static int zaptel_bridge_leave(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+	struct zaptel_mixer *zm = bridge->bridge_pvt;
+	struct zaptel_mixer_channel *zmc = bridge_channel->bridge_pvt;
+	struct zt_confinfo ztc = { 0, };
+
+	/* Take ourselves out of the zaptel mixer structure */
+	AST_LIST_REMOVE(&zm->channels, zmc, list);
+
+	/* Take ourselves out of the conference */
+	ioctl(zmc->fd, ZT_SETCONF, &ztc);
+
+	/* Close down the open file descriptor */
+	close(zmc->fd);
+
+	/* Free the memory and go on our merry way */
+	free(zmc);
+
+	return 0;
+}
+
+static int zaptel_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+{
+	return 0;
+}
+
+static struct ast_bridge_technology zaptel_bridge = {
+	.name = "zaptel_bridge",
+	.capabilities = AST_BRIDGE_CAPABILITY_MULTIMIX,
+	.create = zaptel_bridge_create,
+	.destroy = zaptel_bridge_destroy,
+	.join = zaptel_bridge_join,
+	.leave = zaptel_bridge_leave,
+	.write = zaptel_bridge_write,
+};
+
+static int unload_module(void)
+{
+	return ast_bridge_technology_unregister(&zaptel_bridge);
+}
+
+static int load_module(void)
+{
+	return ast_bridge_technology_register(&zaptel_bridge);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Zaptel mixing bridge module");

Propchange: team/file/bridging/bridges/bridge_zaptel.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/file/bridging/bridges/bridge_zaptel.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/file/bridging/bridges/bridge_zaptel.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the svn-commits mailing list