chan_rtp.c File Reference

RTP (Multicast and Unicast) Media Channel. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/acl.h"
#include "asterisk/app.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/causes.h"
#include "asterisk/format_cache.h"

Include dependency graph for chan_rtp.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
 Function called when our module is loaded.
static struct ast_channelmulticast_rtp_request (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
 Function called when we should prepare to call the multicast destination.
static int rtp_call (struct ast_channel *ast, const char *dest, int timeout)
 Function called when we should actually call the destination.
static int rtp_hangup (struct ast_channel *ast)
 Function called when we should hang the channel up.
static struct ast_framertp_read (struct ast_channel *ast)
 Function called when we should read a frame from the channel.
static int rtp_write (struct ast_channel *ast, struct ast_frame *f)
 Function called when we should write a frame to the channel.
static struct ast_channelunicast_rtp_request (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
 Function called when we should prepare to call the unicast destination.
static int unload_module (void)
 Function called when our module is unloaded.

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "RTP Media Channel" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_channel_tech multicast_rtp_tech
static struct ast_channel_tech unicast_rtp_tech


Detailed Description

RTP (Multicast and Unicast) Media Channel.

Author:
Joshua Colp <jcolp@digium.com>

Andreas 'MacBrody' Broadmann <andreas.brodmann@gmail.com>

Definition in file chan_rtp.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 335 of file chan_rtp.c.

static void __unreg_module ( void   )  [static]

Definition at line 335 of file chan_rtp.c.

static int load_module ( void   )  [static]

static struct ast_channel * multicast_rtp_request ( const char *  type,
struct ast_format_cap cap,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const char *  data,
int *  cause 
) [static, read]

Function called when we should prepare to call the multicast destination.

Definition at line 122 of file chan_rtp.c.

References ao2_cleanup, ao2_ref, args, AST_APP_ARG, AST_CAUSE_FAILURE, ast_channel_alloc, ast_channel_nativeformats_set(), ast_channel_set_rawreadformat(), ast_channel_set_rawwriteformat(), ast_channel_set_readformat(), ast_channel_set_writeformat(), ast_channel_tech_pvt_set(), ast_channel_tech_set(), ast_channel_uniqueid(), ast_channel_unlock, AST_DECLARE_APP_ARGS, ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_format(), ast_log, AST_NONSTANDARD_APP_ARGS, ast_rtp_instance_destroy(), ast_rtp_instance_new(), ast_rtp_instance_set_channel_id(), ast_rtp_instance_set_remote_address, ast_sockaddr_parse(), ast_sockaddr_setnull(), AST_STATE_DOWN, ast_strdupa, ast_strlen_zero, LOG_ERROR, NULL, parse(), and PARSE_PORT_REQUIRE.

00123 {
00124    char *parse;
00125    struct ast_rtp_instance *instance;
00126    struct ast_sockaddr control_address;
00127    struct ast_sockaddr destination_address;
00128    struct ast_channel *chan;
00129    struct ast_format_cap *caps = NULL;
00130    struct ast_format *fmt = NULL;
00131    AST_DECLARE_APP_ARGS(args,
00132       AST_APP_ARG(type);
00133       AST_APP_ARG(destination);
00134       AST_APP_ARG(control);
00135    );
00136 
00137    if (ast_strlen_zero(data)) {
00138       ast_log(LOG_ERROR, "A multicast type and destination must be given to the 'MulticastRTP' channel\n");
00139       goto failure;
00140    }
00141    parse = ast_strdupa(data);
00142    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00143 
00144    fmt = ast_format_cap_get_format(cap, 0);
00145 
00146    ast_sockaddr_setnull(&control_address);
00147 
00148    if (!ast_strlen_zero(args.control) &&
00149       !ast_sockaddr_parse(&control_address, args.control, PARSE_PORT_REQUIRE)) {
00150       ast_log(LOG_ERROR, "Control address '%s' could not be parsed\n", args.control);
00151       goto failure;
00152    }
00153 
00154    if (!ast_sockaddr_parse(&destination_address, args.destination,
00155             PARSE_PORT_REQUIRE)) {
00156       ast_log(LOG_ERROR, "Destination address '%s' could not be parsed\n", args.destination);
00157       goto failure;
00158    }
00159 
00160    caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00161    if (!caps) {
00162       goto failure;
00163    }
00164 
00165    if (!(instance = ast_rtp_instance_new("multicast", NULL, &control_address, args.type))) {
00166       ast_log(LOG_ERROR, "Could not create RTP instance for sending media to '%s'\n", args.destination);
00167       goto failure;
00168    }
00169 
00170    if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", assignedids, requestor, 0, "MulticastRTP/%p", instance))) {
00171       ast_rtp_instance_destroy(instance);
00172       goto failure;
00173    }
00174    ast_rtp_instance_set_channel_id(instance, ast_channel_uniqueid(chan));
00175    ast_rtp_instance_set_remote_address(instance, &destination_address);
00176 
00177    ast_channel_tech_set(chan, &multicast_rtp_tech);
00178 
00179    ast_format_cap_append(caps, fmt, 0);
00180    ast_channel_nativeformats_set(chan, caps);
00181    ast_channel_set_writeformat(chan, fmt);
00182    ast_channel_set_rawwriteformat(chan, fmt);
00183    ast_channel_set_readformat(chan, fmt);
00184    ast_channel_set_rawreadformat(chan, fmt);
00185 
00186    ast_channel_tech_pvt_set(chan, instance);
00187 
00188    ast_channel_unlock(chan);
00189 
00190    ao2_ref(fmt, -1);
00191    ao2_ref(caps, -1);
00192 
00193    return chan;
00194 
00195 failure:
00196    ao2_cleanup(fmt);
00197    ao2_cleanup(caps);
00198    *cause = AST_CAUSE_FAILURE;
00199    return NULL;
00200 }

static int rtp_call ( struct ast_channel ast,
const char *  dest,
int  timeout 
) [static]

Function called when we should actually call the destination.

Definition at line 100 of file chan_rtp.c.

References ast_channel_tech_pvt(), AST_CONTROL_ANSWER, ast_queue_control(), and ast_rtp_instance_activate().

00101 {
00102    struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
00103 
00104    ast_queue_control(ast, AST_CONTROL_ANSWER);
00105 
00106    return ast_rtp_instance_activate(instance);
00107 }

static int rtp_hangup ( struct ast_channel ast  )  [static]

Function called when we should hang the channel up.

Definition at line 110 of file chan_rtp.c.

References ast_channel_tech_pvt(), ast_channel_tech_pvt_set(), ast_rtp_instance_destroy(), and NULL.

00111 {
00112    struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
00113 
00114    ast_rtp_instance_destroy(instance);
00115 
00116    ast_channel_tech_pvt_set(ast, NULL);
00117 
00118    return 0;
00119 }

static struct ast_frame * rtp_read ( struct ast_channel ast  )  [static, read]

Function called when we should read a frame from the channel.

Definition at line 78 of file chan_rtp.c.

References ast_channel_fdno(), ast_channel_tech_pvt(), ast_null_frame, and ast_rtp_instance_read().

00079 {
00080    struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
00081    int fdno = ast_channel_fdno(ast);
00082 
00083    switch (fdno) {
00084    case 0:
00085       return ast_rtp_instance_read(instance, 0);
00086    default:
00087       return &ast_null_frame;
00088    }
00089 }

static int rtp_write ( struct ast_channel ast,
struct ast_frame f 
) [static]

Function called when we should write a frame to the channel.

Definition at line 92 of file chan_rtp.c.

References ast_channel_tech_pvt(), and ast_rtp_instance_write().

00093 {
00094    struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
00095 
00096    return ast_rtp_instance_write(instance, f);
00097 }

static struct ast_channel * unicast_rtp_request ( const char *  type,
struct ast_format_cap cap,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const char *  data,
int *  cause 
) [static, read]

Function called when we should prepare to call the unicast destination.

Definition at line 203 of file chan_rtp.c.

References ao2_cleanup, ao2_ref, args, AST_APP_ARG, AST_CAUSE_FAILURE, ast_channel_alloc, ast_channel_nativeformats_set(), ast_channel_set_fd(), ast_channel_set_rawreadformat(), ast_channel_set_rawwriteformat(), ast_channel_set_readformat(), ast_channel_set_writeformat(), ast_channel_tech_pvt_set(), ast_channel_tech_set(), ast_channel_uniqueid(), ast_channel_unlock, AST_DECLARE_APP_ARGS, ast_format_cache_get, ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_format(), ast_log, AST_NONSTANDARD_APP_ARGS, ast_ouraddrfor(), ast_rtp_instance_destroy(), ast_rtp_instance_fd(), ast_rtp_instance_get_local_address(), ast_rtp_instance_new(), ast_rtp_instance_set_channel_id(), ast_rtp_instance_set_remote_address, ast_sockaddr_parse(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), AST_STATE_DOWN, ast_strdupa, ast_strlen_zero, format, LOG_ERROR, NULL, parse(), PARSE_PORT_REQUIRE, and pbx_builtin_setvar_helper().

00204 {
00205    char *parse;
00206    struct ast_rtp_instance *instance;
00207    struct ast_sockaddr address;
00208    struct ast_sockaddr local_address;
00209    struct ast_channel *chan;
00210    struct ast_format_cap *caps = NULL;
00211    struct ast_format *fmt = NULL;
00212    AST_DECLARE_APP_ARGS(args,
00213       AST_APP_ARG(destination);
00214       AST_APP_ARG(engine);
00215       AST_APP_ARG(format);
00216    );
00217 
00218    if (ast_strlen_zero(data)) {
00219       goto failure;
00220    }
00221    parse = ast_strdupa(data);
00222    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00223 
00224    if (!ast_strlen_zero(args.format)) {
00225       fmt = ast_format_cache_get(args.format);
00226    } else {
00227       fmt = ast_format_cap_get_format(cap, 0);
00228    }
00229 
00230    if (!fmt) {
00231       ast_log(LOG_ERROR, "No format specified for sending RTP to '%s'\n", args.destination);
00232       goto failure;
00233    }
00234 
00235    if (!ast_sockaddr_parse(&address, args.destination,
00236             PARSE_PORT_REQUIRE)) {
00237       ast_log(LOG_ERROR, "Destination '%s' could not be parsed\n", args.destination);
00238       goto failure;
00239    }
00240 
00241    caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00242    if (!caps) {
00243       goto failure;
00244    }
00245 
00246    ast_ouraddrfor(&address, &local_address);
00247    if (!(instance = ast_rtp_instance_new(args.engine, NULL, &local_address, NULL))) {
00248       ast_log(LOG_ERROR, "Could not create RTP instance for sending media to '%s'\n", args.destination);
00249       goto failure;
00250    }
00251 
00252    if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", assignedids, requestor, 0, "UnicastRTP/%s-%p", args.destination, instance))) {
00253       ast_rtp_instance_destroy(instance);
00254       goto failure;
00255    }
00256    ast_rtp_instance_set_channel_id(instance, ast_channel_uniqueid(chan));
00257    ast_rtp_instance_set_remote_address(instance, &address);
00258    ast_channel_set_fd(chan, 0, ast_rtp_instance_fd(instance, 0));
00259 
00260    ast_channel_tech_set(chan, &unicast_rtp_tech);
00261 
00262    ast_format_cap_append(caps, fmt, 0);
00263    ast_channel_nativeformats_set(chan, caps);
00264    ast_channel_set_writeformat(chan, fmt);
00265    ast_channel_set_rawwriteformat(chan, fmt);
00266    ast_channel_set_readformat(chan, fmt);
00267    ast_channel_set_rawreadformat(chan, fmt);
00268 
00269    ast_channel_tech_pvt_set(chan, instance);
00270 
00271    pbx_builtin_setvar_helper(chan, "UNICASTRTP_LOCAL_ADDRESS", ast_sockaddr_stringify_addr(&local_address));
00272    ast_rtp_instance_get_local_address(instance, &local_address);
00273    pbx_builtin_setvar_helper(chan, "UNICASTRTP_LOCAL_PORT", ast_sockaddr_stringify_port(&local_address));
00274 
00275    ast_channel_unlock(chan);
00276 
00277    ao2_ref(fmt, -1);
00278    ao2_ref(caps, -1);
00279 
00280    return chan;
00281 
00282 failure:
00283    ao2_cleanup(fmt);
00284    ao2_cleanup(caps);
00285    *cause = AST_CAUSE_FAILURE;
00286    return NULL;
00287 }

static int unload_module ( void   )  [static]

Function called when our module is unloaded.

Definition at line 290 of file chan_rtp.c.

References ao2_cleanup, ast_channel_unregister(), ast_channel_tech::capabilities, and NULL.


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "RTP Media Channel" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, } [static]

Definition at line 335 of file chan_rtp.c.

Definition at line 335 of file chan_rtp.c.

Definition at line 56 of file chan_rtp.c.

Definition at line 67 of file chan_rtp.c.


Generated on Thu Apr 16 06:29:49 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6