Wed Jan 8 2020 09:50:04

Asterisk developer's documentation


chan_multicast_rtp.c File Reference

Multicast RTP Paging Channel. More...

#include "asterisk.h"
#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"

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. More...
 
static int multicast_rtp_call (struct ast_channel *ast, char *dest, int timeout)
 Function called when we should actually call the destination. More...
 
static int multicast_rtp_hangup (struct ast_channel *ast)
 Function called when we should hang the channel up. More...
 
static struct ast_framemulticast_rtp_read (struct ast_channel *ast)
 Function called when we should read a frame from the channel. More...
 
static struct ast_channelmulticast_rtp_request (const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
 Function called when we should prepare to call the destination. More...
 
static int multicast_rtp_write (struct ast_channel *ast, struct ast_frame *f)
 Function called when we should write a frame to the channel. More...
 
static int unload_module (void)
 Function called when our module is unloaded. More...
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Multicast RTP Paging 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 = "ac1f6a56484a8820659555499174e588" , .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 const char tdesc [] = "Multicast RTP Paging Channel Driver"
 

Detailed Description

Multicast RTP Paging Channel.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om
Andreas 'MacBrody' Broadmann andre.nosp@m.as.b.nosp@m.rodma.nosp@m.nn@g.nosp@m.mail..nosp@m.com

Definition in file chan_multicast_rtp.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 197 of file chan_multicast_rtp.c.

static void __unreg_module ( void  )
static

Definition at line 197 of file chan_multicast_rtp.c.

static int load_module ( void  )
static

Function called when our module is loaded.

Definition at line 175 of file chan_multicast_rtp.c.

References ast_channel_register(), ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and LOG_ERROR.

176 {
178  ast_log(LOG_ERROR, "Unable to register channel class 'MulticastRTP'\n");
180  }
181 
183 }
static struct ast_channel_tech multicast_rtp_tech
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
Definition: channel.c:907
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int multicast_rtp_call ( struct ast_channel ast,
char *  dest,
int  timeout 
)
static

Function called when we should actually call the destination.

Definition at line 92 of file chan_multicast_rtp.c.

References AST_CONTROL_ANSWER, ast_queue_control(), ast_rtp_instance_activate(), and ast_channel::tech_pvt.

93 {
94  struct ast_rtp_instance *instance = ast->tech_pvt;
95 
97 
98  return ast_rtp_instance_activate(instance);
99 }
int ast_rtp_instance_activate(struct ast_rtp_instance *instance)
Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance...
Definition: rtp_engine.c:1744
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
void * tech_pvt
Definition: channel.h:744
static int multicast_rtp_hangup ( struct ast_channel ast)
static

Function called when we should hang the channel up.

Definition at line 102 of file chan_multicast_rtp.c.

References ast_rtp_instance_destroy(), and ast_channel::tech_pvt.

103 {
104  struct ast_rtp_instance *instance = ast->tech_pvt;
105 
106  ast_rtp_instance_destroy(instance);
107 
108  ast->tech_pvt = NULL;
109 
110  return 0;
111 }
void * tech_pvt
Definition: channel.h:744
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:301
static struct ast_frame * multicast_rtp_read ( struct ast_channel ast)
static

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

Definition at line 78 of file chan_multicast_rtp.c.

References ast_null_frame.

79 {
80  return &ast_null_frame;
81 }
struct ast_frame ast_null_frame
Definition: frame.c:131
static struct ast_channel * multicast_rtp_request ( const char *  type,
format_t  format,
const struct ast_channel requestor,
void *  data,
int *  cause 
)
static

Function called when we should prepare to call the destination.

Definition at line 114 of file chan_multicast_rtp.c.

References ast_best_codec(), AST_CAUSE_FAILURE, ast_channel_alloc(), ast_rtp_instance_destroy(), ast_rtp_instance_new(), ast_rtp_instance_set_remote_address(), ast_sockaddr_parse(), ast_sockaddr_setnull(), AST_STATE_DOWN, ast_strdupa, ast_strlen_zero(), ast_channel::linkedid, multicast_rtp_tech, ast_channel::nativeformats, PARSE_PORT_REQUIRE, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.

115 {
116  char *tmp = ast_strdupa(data), *multicast_type = tmp, *destination, *control;
117  struct ast_rtp_instance *instance;
118  struct ast_sockaddr control_address;
119  struct ast_sockaddr destination_address;
120  struct ast_channel *chan;
122 
123  ast_sockaddr_setnull(&control_address);
124 
125  /* If no type was given we can't do anything */
127  goto failure;
128  }
129 
130  if (!(destination = strchr(tmp, '/'))) {
131  goto failure;
132  }
133  *destination++ = '\0';
134 
135  if ((control = strchr(destination, '/'))) {
136  *control++ = '\0';
137  if (!ast_sockaddr_parse(&control_address, control,
139  goto failure;
140  }
141  }
142 
143  if (!ast_sockaddr_parse(&destination_address, destination,
145  goto failure;
146  }
147 
148  if (!(instance = ast_rtp_instance_new("multicast", NULL, &control_address, multicast_type))) {
149  goto failure;
150  }
151 
152  if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", requestor ? requestor->linkedid : "", 0, "MulticastRTP/%p", instance))) {
153  ast_rtp_instance_destroy(instance);
154  goto failure;
155  }
156 
157  ast_rtp_instance_set_remote_address(instance, &destination_address);
158 
159  chan->tech = &multicast_rtp_tech;
160  chan->nativeformats = fmt;
161  chan->writeformat = fmt;
162  chan->readformat = fmt;
163  chan->rawwriteformat = fmt;
164  chan->rawreadformat = fmt;
165  chan->tech_pvt = instance;
166 
167  return chan;
168 
169 failure:
170  *cause = AST_CAUSE_FAILURE;
171  return NULL;
172 }
Main Channel structure associated with a channel.
Definition: channel.h:742
multicast_type
Type of paging to do.
format_t writeformat
Definition: channel.h:854
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:198
void * tech_pvt
Definition: channel.h:744
format_t rawwriteformat
Definition: channel.h:856
static struct ast_channel_tech multicast_rtp_tech
format_t ast_best_codec(format_t fmts)
Pick the best audio codec.
Definition: channel.c:1062
format_t nativeformats
Definition: channel.h:852
const ast_string_field linkedid
Definition: channel.h:787
format_t rawreadformat
Definition: channel.h:855
Socket address structure.
Definition: netsock2.h:63
struct ast_channel * ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *name_fmt,...)
Definition: channel.c:9825
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:106
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
Set the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.c:391
#define AST_CAUSE_FAILURE
Definition: causes.h:149
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
int64_t format_t
Definition: frame_defs.h:32
struct ast_rtp_instance * ast_rtp_instance_new(const char *engine_name, struct sched_context *sched, const struct ast_sockaddr *sa, void *data)
Create a new RTP instance.
Definition: rtp_engine.c:308
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:301
format_t readformat
Definition: channel.h:853
static snd_pcm_format_t format
Definition: chan_alsa.c:93
struct ast_channel_tech * tech
Definition: channel.h:743
static int multicast_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 84 of file chan_multicast_rtp.c.

References ast_rtp_instance_write(), and ast_channel::tech_pvt.

85 {
86  struct ast_rtp_instance *instance = ast->tech_pvt;
87 
88  return ast_rtp_instance_write(instance, f);
89 }
void * tech_pvt
Definition: channel.h:744
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
Definition: rtp_engine.c:374
static int unload_module ( void  )
static

Function called when our module is unloaded.

Definition at line 186 of file chan_multicast_rtp.c.

References ast_channel_unregister().

187 {
189 
190  return 0;
191 }
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
Definition: channel.c:938
static struct ast_channel_tech multicast_rtp_tech

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Multicast RTP Paging 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, }
static

Definition at line 197 of file chan_multicast_rtp.c.

Definition at line 197 of file chan_multicast_rtp.c.

struct ast_channel_tech multicast_rtp_tech
static

Definition at line 66 of file chan_multicast_rtp.c.

Referenced by multicast_rtp_request().

const char tdesc[] = "Multicast RTP Paging Channel Driver"
static

Definition at line 56 of file chan_multicast_rtp.c.