[asterisk-commits] file: branch file/issue11797 r187489 - /team/file/issue11797/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 9 14:01:23 CDT 2009


Author: file
Date: Thu Apr  9 14:01:20 2009
New Revision: 187489

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=187489
Log:
Add the basis of the res_rtp_multicast module so I can look at other things.

Added:
    team/file/issue11797/res/res_rtp_multicast.c   (with props)

Added: team/file/issue11797/res/res_rtp_multicast.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/issue11797/res/res_rtp_multicast.c?view=auto&rev=187489
==============================================================================
--- team/file/issue11797/res/res_rtp_multicast.c (added)
+++ team/file/issue11797/res/res_rtp_multicast.c Thu Apr  9 14:01:20 2009
@@ -1,0 +1,205 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2009, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ * Andreas 'MacBrody' Brodmann <andreas.brodmann at gmail.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 Multicast RTP Paging Engine
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ * \author Andreas 'MacBrody' Brodmann <andreas.brodmann at gmail.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <sys/time.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <math.h>
+
+#include "asterisk/pbx.h"
+#include "asterisk/frame.h"
+#include "asterisk/channel.h"
+#include "asterisk/acl.h"
+#include "asterisk/config.h"
+#include "asterisk/lock.h"
+#include "asterisk/utils.h"
+#include "asterisk/netsock.h"
+#include "asterisk/cli.h"
+#include "asterisk/manager.h"
+#include "asterisk/unaligned.h"
+#include "asterisk/module.h"
+#include "asterisk/rtp_engine.h"
+
+/*! Command value used for Linksys paging to indicate we are starting */
+#define LINKSYS_MCAST_STARTCMD 6
+
+/*! Command value used for Linksys paging to indicate we are stopping */
+#define LINKSYS_MCAST_STOPCMD 7
+
+/*! \brief Type of paging to do */
+enum multicast_type {
+	/*! Simple multicast enabled client/receiver paging like Snom and Barix uses */
+	MULTICAST_TYPE_BASIC = 0,
+	/*! More advanced Linksys type paging which requires a start and stop packet */
+	MULTICAST_TYPE_LINKSYS,
+};
+
+/*! \brief Structure for a Linksys control packet */
+struct multicast_control_packet {
+	/*! Unique identifier for the control packet */
+	uint32_t unique_id;
+	/*! Actual command in the control packet */
+	uint32_t command;
+	/*! IP address for the RTP */
+	uint32_t ip;
+	/*! Port for the RTP */
+	uint32_t port;
+};
+
+/*! \brief Structure for a multicast paging instance */
+struct multicast_rtp {
+	/*! TYpe of multicast paging this instance is doing */
+	enum multicast_type type;
+	/*! Socket used for sending the audio on */
+	int socket;
+	/*! Control address used for Linksys paging */
+	struct sockaddr_in control_address;
+};
+
+/* Forward Declarations */
+static int multicast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data);
+static int multicast_rtp_activate(struct ast_rtp_instance *instance);
+static int multicast_rtp_destroy(struct ast_rtp_instance *instance);
+static int multicast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *frame);
+static struct ast_frame *multicast_rtp_read(struct ast_rtp_instance *instance, int rtcp);
+
+/* RTP Engine Declaration */
+static struct ast_rtp_engine multicast_rtp_engine = {
+	.name = "multicast",
+	.new = multicast_rtp_new,
+	.activate = multicast_rtp_activate,
+	.destroy = multicast_rtp_destroy,
+	.write = multicast_rtp_write,
+	.read = multicast_rtp_read,
+};
+
+/*! \brief Function called to create a new multicast instance */
+static int multicast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data)
+{
+	struct multicast_rtp *multicast;
+	const char *type = data;
+
+	if (!(multicast = ast_calloc(1, sizeof(*multicast)))) {
+		return -1;
+	}
+
+	if (!strcasecmp(type, "basic")) {
+		multicast->type = MULTICAST_TYPE_BASIC;
+	} else if (!strcasecmp(type, "linksys")) {
+		multicast->type = MULTICAST_TYPE_LINKSYS;
+	} else {
+		ast_free(multicast);
+		return -1;
+	}
+
+	if ((multicast->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+		ast_free(multicast);
+		return -1;
+	}
+
+	ast_rtp_instance_set_data(instance, multicast);
+
+	return 0;
+}
+
+/*! \brief Function called to indicate that audio is now going to flow */
+static int multicast_rtp_activate(struct ast_rtp_instance *instance)
+{
+	struct multicast_rtp *multicast = ast_rtp_instance_get_data(instance);
+
+	if (multicast->type == MULTICAST_TYPE_LINKSYS) {
+		struct multicast_control_packet control_packet = { 0, };
+	}
+
+	return 0;
+}
+
+/*! \brief Function called to destroy a multicast instance */
+static int multicast_rtp_destroy(struct ast_rtp_instance *instance)
+{
+	struct multicast_rtp *multicast = ast_rtp_instance_get_data(instance);
+
+	if (multicast->type == MULTICAST_TYPE_LINKSYS) {
+		struct multicast_control_packet control_packet = { 0, };
+	}
+
+	close(multicast->socket);
+
+	ast_free(multicast);
+
+	return 0;
+}
+
+/*! \brief Function called to broadcast some audio on a multicast instance */
+static int multicast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
+{
+	struct multicast_rtp *multicast = ast_rtp_instance_get_data(instance);
+	struct sockaddr_in remote_address;
+	int hdrlen = 12, res;
+	unsigned char *rtpheader = (unsigned char *)(frame->data.ptr - hdrlen);
+
+	/* We only accept audio, nothing else */
+	if (frame->frametype != AST_FRAME_VOICE) {
+		return 0;
+	}
+
+	ast_rtp_instance_get_remote_address(instance, &remote_address);
+
+	return -1;
+}
+
+/*! \brief Function called to read from a multicast instance */
+static struct ast_frame *multicast_rtp_read(struct ast_rtp_instance *instance, int rtcp)
+{
+	return &ast_null_frame;
+}
+
+static int load_module(void)
+{
+	if (ast_rtp_engine_register(&multicast_rtp_engine)) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	ast_rtp_engine_unregister(&multicast_rtp_engine);
+
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Multicast Paging RTP Engine",
+		.load = load_module,
+		.unload = unload_module,
+		);

Propchange: team/file/issue11797/res/res_rtp_multicast.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/file/issue11797/res/res_rtp_multicast.c
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Propchange: team/file/issue11797/res/res_rtp_multicast.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list