2009-06-25 18:25:24 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Joshua Colp <jcolp@digium.com>
|
|
|
|
* Andreas 'MacBrody' Brodmann <andreas.brodmann@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
|
|
|
|
*
|
|
|
|
* \author Joshua Colp <jcolp@digium.com>
|
|
|
|
* \author Andreas 'MacBrody' Broadmann <andreas.brodmann@gmail.com>
|
|
|
|
*
|
|
|
|
* \brief Multicast RTP Paging Channel
|
|
|
|
*
|
|
|
|
* \ingroup channel_drivers
|
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2009-06-25 18:25:24 +00:00
|
|
|
#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/acl.h"
|
|
|
|
#include "asterisk/callerid.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
#include "asterisk/rtp_engine.h"
|
|
|
|
#include "asterisk/causes.h"
|
|
|
|
|
|
|
|
static const char tdesc[] = "Multicast RTP Paging Channel Driver";
|
|
|
|
|
|
|
|
/* Forward declarations */
|
2012-02-01 19:53:38 +00:00
|
|
|
static struct ast_channel *multicast_rtp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause);
|
|
|
|
static int multicast_rtp_call(struct ast_channel *ast, const char *dest, int timeout);
|
2009-06-25 18:25:24 +00:00
|
|
|
static int multicast_rtp_hangup(struct ast_channel *ast);
|
|
|
|
static struct ast_frame *multicast_rtp_read(struct ast_channel *ast);
|
|
|
|
static int multicast_rtp_write(struct ast_channel *ast, struct ast_frame *f);
|
|
|
|
|
|
|
|
/* Channel driver declaration */
|
2011-02-03 16:22:10 +00:00
|
|
|
static struct ast_channel_tech multicast_rtp_tech = {
|
2009-06-25 18:25:24 +00:00
|
|
|
.type = "MulticastRTP",
|
|
|
|
.description = tdesc,
|
|
|
|
.requester = multicast_rtp_request,
|
|
|
|
.call = multicast_rtp_call,
|
|
|
|
.hangup = multicast_rtp_hangup,
|
|
|
|
.read = multicast_rtp_read,
|
|
|
|
.write = multicast_rtp_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief Function called when we should read a frame from the channel */
|
|
|
|
static struct ast_frame *multicast_rtp_read(struct ast_channel *ast)
|
|
|
|
{
|
|
|
|
return &ast_null_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Function called when we should write a frame to the channel */
|
|
|
|
static int multicast_rtp_write(struct ast_channel *ast, struct ast_frame *f)
|
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
|
|
|
return ast_rtp_instance_write(instance, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Function called when we should actually call the destination */
|
2012-02-01 19:53:38 +00:00
|
|
|
static int multicast_rtp_call(struct ast_channel *ast, const char *dest, int timeout)
|
2009-06-25 18:25:24 +00:00
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
|
|
|
ast_queue_control(ast, AST_CONTROL_ANSWER);
|
|
|
|
|
|
|
|
return ast_rtp_instance_activate(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Function called when we should hang the channel up */
|
|
|
|
static int multicast_rtp_hangup(struct ast_channel *ast)
|
|
|
|
{
|
2012-02-20 23:43:27 +00:00
|
|
|
struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
|
|
|
ast_rtp_instance_destroy(instance);
|
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_tech_pvt_set(ast, NULL);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Function called when we should prepare to call the destination */
|
2012-02-01 19:53:38 +00:00
|
|
|
static struct ast_channel *multicast_rtp_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause)
|
2009-06-25 18:25:24 +00:00
|
|
|
{
|
|
|
|
char *tmp = ast_strdupa(data), *multicast_type = tmp, *destination, *control;
|
|
|
|
struct ast_rtp_instance *instance;
|
2011-01-14 20:18:26 +00:00
|
|
|
struct ast_sockaddr control_address;
|
2010-07-08 22:08:07 +00:00
|
|
|
struct ast_sockaddr destination_address;
|
2009-06-25 18:25:24 +00:00
|
|
|
struct ast_channel *chan;
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format fmt;
|
|
|
|
ast_best_codec(cap, &fmt);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
2011-01-14 20:18:26 +00:00
|
|
|
ast_sockaddr_setnull(&control_address);
|
|
|
|
|
2009-06-25 18:25:24 +00:00
|
|
|
/* If no type was given we can't do anything */
|
|
|
|
if (ast_strlen_zero(multicast_type)) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(destination = strchr(tmp, '/'))) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
*destination++ = '\0';
|
|
|
|
|
|
|
|
if ((control = strchr(destination, '/'))) {
|
|
|
|
*control++ = '\0';
|
2010-07-08 22:08:07 +00:00
|
|
|
if (!ast_sockaddr_parse(&control_address, control,
|
|
|
|
PARSE_PORT_REQUIRE)) {
|
2009-06-25 18:25:24 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 11:54:00 +00:00
|
|
|
if (!ast_sockaddr_parse(&destination_address, destination,
|
|
|
|
PARSE_PORT_REQUIRE)) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-06-25 18:25:24 +00:00
|
|
|
if (!(instance = ast_rtp_instance_new("multicast", NULL, &control_address, multicast_type))) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", requestor ? ast_channel_linkedid(requestor) : "", 0, "MulticastRTP/%p", instance))) {
|
2009-06-25 18:25:24 +00:00
|
|
|
ast_rtp_instance_destroy(instance);
|
|
|
|
goto failure;
|
|
|
|
}
|
2013-07-05 17:33:33 +00:00
|
|
|
ast_rtp_instance_set_channel_id(instance, ast_channel_uniqueid(chan));
|
2009-06-25 18:25:24 +00:00
|
|
|
ast_rtp_instance_set_remote_address(instance, &destination_address);
|
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_tech_set(chan, &multicast_rtp_tech);
|
2011-02-03 16:22:10 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_format_cap_add(ast_channel_nativeformats(chan), &fmt);
|
2012-02-24 00:32:20 +00:00
|
|
|
ast_format_copy(ast_channel_writeformat(chan), &fmt);
|
|
|
|
ast_format_copy(ast_channel_rawwriteformat(chan), &fmt);
|
|
|
|
ast_format_copy(ast_channel_readformat(chan), &fmt);
|
|
|
|
ast_format_copy(ast_channel_rawreadformat(chan), &fmt);
|
2011-02-03 16:22:10 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_tech_pvt_set(chan, instance);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
|
|
|
return chan;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
*cause = AST_CAUSE_FAILURE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Function called when our module is loaded */
|
|
|
|
static int load_module(void)
|
|
|
|
{
|
2011-02-03 16:22:10 +00:00
|
|
|
if (!(multicast_rtp_tech.capabilities = ast_format_cap_alloc())) {
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
ast_format_cap_add_all(multicast_rtp_tech.capabilities);
|
2009-06-25 18:25:24 +00:00
|
|
|
if (ast_channel_register(&multicast_rtp_tech)) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to register channel class 'MulticastRTP'\n");
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Function called when our module is unloaded */
|
|
|
|
static int unload_module(void)
|
|
|
|
{
|
|
|
|
ast_channel_unregister(&multicast_rtp_tech);
|
2011-02-03 16:22:10 +00:00
|
|
|
multicast_rtp_tech.capabilities = ast_format_cap_destroy(multicast_rtp_tech.capabilities);
|
2009-06-25 18:25:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-20 19:35:02 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Multicast RTP Paging Channel",
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
.load_pri = AST_MODPRI_CHANNEL_DRIVER,
|
|
|
|
);
|