Wed Jan 27 20:02:07 2016

Asterisk developer's documentation


chan_multicast_rtp.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2009, Digium, Inc.
00005  *
00006  * Joshua Colp <jcolp@digium.com>
00007  * Andreas 'MacBrody' Brodmann <andreas.brodmann@gmail.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*! \file
00021  *
00022  * \author Joshua Colp <jcolp@digium.com>
00023  * \author Andreas 'MacBrody' Broadmann <andreas.brodmann@gmail.com>
00024  *
00025  * \brief Multicast RTP Paging Channel
00026  *
00027  * \ingroup channel_drivers
00028  */
00029 
00030 /*** MODULEINFO
00031    <support_level>core</support_level>
00032  ***/
00033 
00034 #include "asterisk.h"
00035 
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 385683 $")
00037 
00038 #include <fcntl.h>
00039 #include <sys/signal.h>
00040 
00041 #include "asterisk/lock.h"
00042 #include "asterisk/channel.h"
00043 #include "asterisk/config.h"
00044 #include "asterisk/module.h"
00045 #include "asterisk/pbx.h"
00046 #include "asterisk/sched.h"
00047 #include "asterisk/io.h"
00048 #include "asterisk/acl.h"
00049 #include "asterisk/callerid.h"
00050 #include "asterisk/file.h"
00051 #include "asterisk/cli.h"
00052 #include "asterisk/app.h"
00053 #include "asterisk/rtp_engine.h"
00054 #include "asterisk/causes.h"
00055 
00056 static const char tdesc[] = "Multicast RTP Paging Channel Driver";
00057 
00058 /* Forward declarations */
00059 static struct ast_channel *multicast_rtp_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
00060 static int multicast_rtp_call(struct ast_channel *ast, char *dest, int timeout);
00061 static int multicast_rtp_hangup(struct ast_channel *ast);
00062 static struct ast_frame *multicast_rtp_read(struct ast_channel *ast);
00063 static int multicast_rtp_write(struct ast_channel *ast, struct ast_frame *f);
00064 
00065 /* Channel driver declaration */
00066 static const struct ast_channel_tech multicast_rtp_tech = {
00067    .type = "MulticastRTP",
00068    .description = tdesc,
00069    .capabilities = -1,
00070    .requester = multicast_rtp_request,
00071    .call = multicast_rtp_call,
00072    .hangup = multicast_rtp_hangup,
00073    .read = multicast_rtp_read,
00074    .write = multicast_rtp_write,
00075 };
00076 
00077 /*! \brief Function called when we should read a frame from the channel */
00078 static struct ast_frame  *multicast_rtp_read(struct ast_channel *ast)
00079 {
00080    return &ast_null_frame;
00081 }
00082 
00083 /*! \brief Function called when we should write a frame to the channel */
00084 static int multicast_rtp_write(struct ast_channel *ast, struct ast_frame *f)
00085 {
00086    struct ast_rtp_instance *instance = ast->tech_pvt;
00087 
00088    return ast_rtp_instance_write(instance, f);
00089 }
00090 
00091 /*! \brief Function called when we should actually call the destination */
00092 static int multicast_rtp_call(struct ast_channel *ast, char *dest, int timeout)
00093 {
00094    struct ast_rtp_instance *instance = ast->tech_pvt;
00095 
00096    ast_queue_control(ast, AST_CONTROL_ANSWER);
00097 
00098    return ast_rtp_instance_activate(instance);
00099 }
00100 
00101 /*! \brief Function called when we should hang the channel up */
00102 static int multicast_rtp_hangup(struct ast_channel *ast)
00103 {
00104    struct ast_rtp_instance *instance = ast->tech_pvt;
00105 
00106    ast_rtp_instance_destroy(instance);
00107 
00108    ast->tech_pvt = NULL;
00109 
00110    return 0;
00111 }
00112 
00113 /*! \brief Function called when we should prepare to call the destination */
00114 static struct ast_channel *multicast_rtp_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
00115 {
00116    char *tmp = ast_strdupa(data), *multicast_type = tmp, *destination, *control;
00117    struct ast_rtp_instance *instance;
00118    struct ast_sockaddr control_address;
00119    struct ast_sockaddr destination_address;
00120    struct ast_channel *chan;
00121    format_t fmt = ast_best_codec(format);
00122 
00123    ast_sockaddr_setnull(&control_address);
00124 
00125    /* If no type was given we can't do anything */
00126    if (ast_strlen_zero(multicast_type)) {
00127       goto failure;
00128    }
00129 
00130    if (!(destination = strchr(tmp, '/'))) {
00131       goto failure;
00132    }
00133    *destination++ = '\0';
00134 
00135    if ((control = strchr(destination, '/'))) {
00136       *control++ = '\0';
00137       if (!ast_sockaddr_parse(&control_address, control,
00138                PARSE_PORT_REQUIRE)) {
00139          goto failure;
00140       }
00141    }
00142 
00143    if (!ast_sockaddr_parse(&destination_address, destination,
00144             PARSE_PORT_REQUIRE)) {
00145       goto failure;
00146    }
00147 
00148    if (!(instance = ast_rtp_instance_new("multicast", NULL, &control_address, multicast_type))) {
00149       goto failure;
00150    }
00151 
00152    if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", requestor ? requestor->linkedid : "", 0, "MulticastRTP/%p", instance))) {
00153       ast_rtp_instance_destroy(instance);
00154       goto failure;
00155    }
00156 
00157    ast_rtp_instance_set_remote_address(instance, &destination_address);
00158 
00159    chan->tech = &multicast_rtp_tech;
00160    chan->nativeformats = fmt;
00161    chan->writeformat = fmt;
00162    chan->readformat = fmt;
00163    chan->rawwriteformat = fmt;
00164    chan->rawreadformat = fmt;
00165    chan->tech_pvt = instance;
00166 
00167    return chan;
00168 
00169 failure:
00170    *cause = AST_CAUSE_FAILURE;
00171    return NULL;
00172 }
00173 
00174 /*! \brief Function called when our module is loaded */
00175 static int load_module(void)
00176 {
00177    if (ast_channel_register(&multicast_rtp_tech)) {
00178       ast_log(LOG_ERROR, "Unable to register channel class 'MulticastRTP'\n");
00179       return AST_MODULE_LOAD_DECLINE;
00180    }
00181 
00182    return AST_MODULE_LOAD_SUCCESS;
00183 }
00184 
00185 /*! \brief Function called when our module is unloaded */
00186 static int unload_module(void)
00187 {
00188    ast_channel_unregister(&multicast_rtp_tech);
00189 
00190    return 0;
00191 }
00192 
00193 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Multicast RTP Paging Channel",
00194    .load = load_module,
00195    .unload = unload_module,
00196    .load_pri = AST_MODPRI_CHANNEL_DRIVER,
00197 );

Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1