Asterisk - The Open Source Telephony Project  18.5.0
Enumerations | Functions | Variables
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 "asterisk/multicast_rtp.h"
#include "asterisk/dns_core.h"
Include dependency graph for chan_rtp.c:

Go to the source code of this file.

Enumerations

enum  { OPT_RTP_CODEC = (1 << 0), OPT_RTP_ENGINE = (1 << 1) }
 
enum  { OPT_ARG_RTP_CODEC, OPT_ARG_RTP_ENGINE, OPT_ARG_ARRAY_SIZE }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_formatderive_format_from_cap (struct ast_format_cap *cap)
 
static int load_module (void)
 Function called when our module is loaded. More...
 
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. More...
 
static int rtp_call (struct ast_channel *ast, const char *dest, int timeout)
 Function called when we should actually call the destination. More...
 
static int rtp_hangup (struct ast_channel *ast)
 Function called when we should hang the channel up. More...
 
static struct ast_framertp_read (struct ast_channel *ast)
 Function called when we should read a frame from the channel. More...
 
static int rtp_write (struct ast_channel *ast, struct ast_frame *f)
 Function called when we should write a frame to the channel. More...
 
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. 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 = "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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, .requires = "res_rtp_multicast", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_channel_tech multicast_rtp_tech
 
static const struct ast_app_option unicast_rtp_options [128] = { [ 'c' ] = { .flag = OPT_RTP_CODEC , .arg_index = OPT_ARG_RTP_CODEC + 1 }, [ 'e' ] = { .flag = OPT_RTP_ENGINE , .arg_index = OPT_ARG_RTP_ENGINE + 1 }, }
 
static struct ast_channel_tech unicast_rtp_tech
 

Detailed Description

RTP (Multicast and Unicast) Media 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_rtp.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPT_RTP_CODEC 
OPT_RTP_ENGINE 

Definition at line 249 of file chan_rtp.c.

249  {
250  OPT_RTP_CODEC = (1 << 0),
251  OPT_RTP_ENGINE = (1 << 1),
252 };

◆ anonymous enum

anonymous enum
Enumerator
OPT_ARG_RTP_CODEC 
OPT_ARG_RTP_ENGINE 
OPT_ARG_ARRAY_SIZE 

Definition at line 254 of file chan_rtp.c.

254  {
257  /* note: this entry _MUST_ be the last one in the enum */
259 };

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 451 of file chan_rtp.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 451 of file chan_rtp.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 451 of file chan_rtp.c.

◆ derive_format_from_cap()

static struct ast_format* derive_format_from_cap ( struct ast_format_cap cap)
static

Definition at line 122 of file chan_rtp.c.

References ast_format_cap_count(), ast_format_cap_get_format(), ast_format_slin, and ast_format_ulaw.

Referenced by multicast_rtp_request(), and unicast_rtp_request().

123 {
124  struct ast_format *fmt = ast_format_cap_get_format(cap, 0);
125 
126  if (ast_format_cap_count(cap) == 1 && fmt == ast_format_slin) {
127  /*
128  * Because we have no SDP, we must use one of the static RTP payload
129  * assignments. Signed linear @ 8kHz does not map, so if that is our
130  * only capability, we force μ-law instead.
131  */
132  fmt = ast_format_ulaw;
133  }
134 
135  return fmt;
136 }
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
Definition of a media format.
Definition: format.c:43
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41

◆ load_module()

static int load_module ( void  )
static

Function called when our module is loaded.

Definition at line 419 of file chan_rtp.c.

References ast_channel_register(), ast_format_cap_alloc, ast_format_cap_append_by_type(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_log, AST_MEDIA_TYPE_UNKNOWN, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CHANNEL_DRIVER, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, ast_channel_tech::capabilities, LOG_ERROR, and unload_module().

420 {
423  }
426  ast_log(LOG_ERROR, "Unable to register channel class 'MulticastRTP'\n");
427  unload_module();
429  }
430 
432  unload_module();
434  }
437  ast_log(LOG_ERROR, "Unable to register channel class 'UnicastRTP'\n");
438  unload_module();
440  }
441 
443 }
static struct ast_channel_tech multicast_rtp_tech
Definition: chan_rtp.c:57
static int unload_module(void)
Function called when our module is unloaded.
Definition: chan_rtp.c:405
int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Add all codecs Asterisk knows about for a specific type to the capabilities structure.
Definition: format_cap.c:216
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:539
#define ast_log
Definition: astobj2.c:42
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
#define LOG_ERROR
Definition: logger.h:285
struct ast_format_cap * capabilities
Definition: channel.h:633
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_channel_tech unicast_rtp_tech
Definition: chan_rtp.c:68

◆ multicast_rtp_request()

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

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

Definition at line 139 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_log, ast_multicast_rtp_create_options(), ast_multicast_rtp_free_options(), ast_multicast_rtp_options_get_format(), 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, derive_format_from_cap(), LOG_ERROR, NULL, options, parse(), and PARSE_PORT_REQUIRE.

140 {
141  char *parse;
142  struct ast_rtp_instance *instance;
143  struct ast_sockaddr control_address;
144  struct ast_sockaddr destination_address;
145  struct ast_channel *chan;
146  struct ast_format_cap *caps = NULL;
147  struct ast_format *fmt = NULL;
149  AST_APP_ARG(type);
150  AST_APP_ARG(destination);
151  AST_APP_ARG(control);
153  );
154  struct ast_multicast_rtp_options *mcast_options = NULL;
155 
156  if (ast_strlen_zero(data)) {
157  ast_log(LOG_ERROR, "A multicast type and destination must be given to the 'MulticastRTP' channel\n");
158  goto failure;
159  }
160  parse = ast_strdupa(data);
161  AST_NONSTANDARD_APP_ARGS(args, parse, '/');
162 
163  if (ast_strlen_zero(args.type)) {
164  ast_log(LOG_ERROR, "Type is required for the 'MulticastRTP' channel\n");
165  goto failure;
166  }
167 
168  if (ast_strlen_zero(args.destination)) {
169  ast_log(LOG_ERROR, "Destination is required for the 'MulticastRTP' channel\n");
170  goto failure;
171  }
172  if (!ast_sockaddr_parse(&destination_address, args.destination, PARSE_PORT_REQUIRE)) {
173  ast_log(LOG_ERROR, "Destination address '%s' could not be parsed\n",
174  args.destination);
175  goto failure;
176  }
177 
178  ast_sockaddr_setnull(&control_address);
179  if (!ast_strlen_zero(args.control)
180  && !ast_sockaddr_parse(&control_address, args.control, PARSE_PORT_REQUIRE)) {
181  ast_log(LOG_ERROR, "Control address '%s' could not be parsed\n", args.control);
182  goto failure;
183  }
184 
185  mcast_options = ast_multicast_rtp_create_options(args.type, args.options);
186  if (!mcast_options) {
187  goto failure;
188  }
189 
190  fmt = ast_multicast_rtp_options_get_format(mcast_options);
191  if (!fmt) {
192  fmt = derive_format_from_cap(cap);
193  }
194  if (!fmt) {
195  ast_log(LOG_ERROR, "No codec available for sending RTP to '%s'\n",
196  args.destination);
197  goto failure;
198  }
199 
201  if (!caps) {
202  goto failure;
203  }
204 
205  instance = ast_rtp_instance_new("multicast", NULL, &control_address, mcast_options);
206  if (!instance) {
208  "Could not create '%s' multicast RTP instance for sending media to '%s'\n",
209  args.type, args.destination);
210  goto failure;
211  }
212 
213  chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", assignedids,
214  requestor, 0, "MulticastRTP/%p", instance);
215  if (!chan) {
216  ast_rtp_instance_destroy(instance);
217  goto failure;
218  }
220  ast_rtp_instance_set_remote_address(instance, &destination_address);
221 
223 
224  ast_format_cap_append(caps, fmt, 0);
225  ast_channel_nativeformats_set(chan, caps);
226  ast_channel_set_writeformat(chan, fmt);
228  ast_channel_set_readformat(chan, fmt);
230 
231  ast_channel_tech_pvt_set(chan, instance);
232 
233  ast_channel_unlock(chan);
234 
235  ao2_ref(fmt, -1);
236  ao2_ref(caps, -1);
237  ast_multicast_rtp_free_options(mcast_options);
238 
239  return chan;
240 
241 failure:
242  ao2_cleanup(fmt);
243  ao2_cleanup(caps);
244  ast_multicast_rtp_free_options(mcast_options);
245  *cause = AST_CAUSE_FAILURE;
246  return NULL;
247 }
static const char type[]
Definition: chan_ooh323.c:109
Main Channel structure associated with a channel.
static struct ast_format * derive_format_from_cap(struct ast_format_cap *cap)
Definition: chan_rtp.c:122
static struct ast_channel_tech multicast_rtp_tech
Definition: chan_rtp.c:57
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
Definition: rtp_engine.c:553
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:230
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
Definition of a media format.
Definition: format.c:43
struct ast_format * ast_multicast_rtp_options_get_format(struct ast_multicast_rtp_options *mcast_options)
Get format specified in multicast options.
const char * args
#define NULL
Definition: resample.c:96
Socket address structure.
Definition: netsock2.h:97
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:140
#define ast_strlen_zero(foo)
Definition: strings.h:52
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
struct ast_multicast_rtp_options * ast_multicast_rtp_create_options(const char *type, const char *options)
Create multicast RTP options.
#define ast_log
Definition: astobj2.c:42
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define AST_CAUSE_FAILURE
Definition: causes.h:149
#define LOG_ERROR
Definition: logger.h:285
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the &#39;nonstandard&#39; argument separation process for an application.
#define ast_rtp_instance_set_remote_address(instance, address)
Set the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.h:1080
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:458
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_multicast_rtp_free_options(struct ast_multicast_rtp_options *mcast_options)
Free multicast RTP options.
static struct test_options options
struct ast_rtp_instance * ast_rtp_instance_new(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
Create a new RTP instance.
Definition: rtp_engine.c:465
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ rtp_call()

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 101 of file chan_rtp.c.

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

102 {
103  struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
104 
106 
107  return ast_rtp_instance_activate(instance);
108 }
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:2647
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1231
void * ast_channel_tech_pvt(const struct ast_channel *chan)

◆ rtp_hangup()

static int rtp_hangup ( struct ast_channel ast)
static

Function called when we should hang the channel up.

Definition at line 111 of file chan_rtp.c.

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

112 {
113  struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
114 
115  ast_rtp_instance_destroy(instance);
116 
118 
119  return 0;
120 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define NULL
Definition: resample.c:96
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:458
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)

◆ rtp_read()

static struct ast_frame * rtp_read ( struct ast_channel ast)
static

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

Definition at line 79 of file chan_rtp.c.

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

80 {
81  struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
82  int fdno = ast_channel_fdno(ast);
83 
84  switch (fdno) {
85  case 0:
86  return ast_rtp_instance_read(instance, 0);
87  default:
88  return &ast_null_frame;
89  }
90 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
int ast_channel_fdno(const struct ast_channel *chan)
struct ast_frame ast_null_frame
Definition: main/frame.c:79
struct ast_frame * ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
Receive a frame over RTP.
Definition: rtp_engine.c:578

◆ rtp_write()

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 93 of file chan_rtp.c.

References ast_channel_tech_pvt(), and ast_rtp_instance_write().

94 {
95  struct ast_rtp_instance *instance = ast_channel_tech_pvt(ast);
96 
97  return ast_rtp_instance_write(instance, f);
98 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
Definition: rtp_engine.c:568

◆ unicast_rtp_request()

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

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

Definition at line 269 of file chan_rtp.c.

References ao2_cleanup, ao2_ref, args, AST_APP_ARG, ast_app_parse_options(), 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_dns_resolve_ipv6_and_ipv4(), ast_format_cache_get, ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, 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_copy(), ast_sockaddr_parse(), ast_sockaddr_split_hostport(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), AST_STATE_DOWN, ast_strdupa, ast_strlen_zero, ast_test_flag, derive_format_from_cap(), host, LOG_ERROR, NULL, OPT_ARG_ARRAY_SIZE, OPT_ARG_RTP_CODEC, OPT_ARG_RTP_ENGINE, OPT_RTP_CODEC, OPT_RTP_ENGINE, options, parse(), PARSE_PORT_REQUIRE, pbx_builtin_setvar_helper(), S_COR, S_OR, and unicast_rtp_options.

270 {
271  char *parse;
272  struct ast_rtp_instance *instance;
273  struct ast_sockaddr address;
274  struct ast_sockaddr local_address;
275  struct ast_channel *chan;
276  struct ast_format_cap *caps = NULL;
277  struct ast_format *fmt = NULL;
278  const char *engine_name;
280  AST_APP_ARG(destination);
282  );
283  struct ast_flags opts = { 0, };
284  char *opt_args[OPT_ARG_ARRAY_SIZE];
285 
286  if (ast_strlen_zero(data)) {
287  ast_log(LOG_ERROR, "Destination is required for the 'UnicastRTP' channel\n");
288  goto failure;
289  }
290  parse = ast_strdupa(data);
291  AST_NONSTANDARD_APP_ARGS(args, parse, '/');
292 
293  if (ast_strlen_zero(args.destination)) {
294  ast_log(LOG_ERROR, "Destination is required for the 'UnicastRTP' channel\n");
295  goto failure;
296  }
297 
298  if (!ast_sockaddr_parse(&address, args.destination, PARSE_PORT_REQUIRE)) {
299  int rc;
300  char *host;
301  char *port;
302 
303  rc = ast_sockaddr_split_hostport(args.destination, &host, &port, PARSE_PORT_REQUIRE);
304  if (!rc) {
305  ast_log(LOG_ERROR, "Unable to parse destination '%s' into host and port\n", args.destination);
306  goto failure;
307  }
308 
309  rc = ast_dns_resolve_ipv6_and_ipv4(&address, host, port);
310  if (rc != 0) {
311  ast_log(LOG_ERROR, "Unable to resolve host '%s'\n", host);
312  goto failure;
313  }
314  }
315 
316  if (!ast_strlen_zero(args.options)
317  && ast_app_parse_options(unicast_rtp_options, &opts, opt_args,
318  ast_strdupa(args.options))) {
319  ast_log(LOG_ERROR, "'UnicastRTP' channel options '%s' parse error\n",
320  args.options);
321  goto failure;
322  }
323 
324  if (ast_test_flag(&opts, OPT_RTP_CODEC)
325  && !ast_strlen_zero(opt_args[OPT_ARG_RTP_CODEC])) {
326  fmt = ast_format_cache_get(opt_args[OPT_ARG_RTP_CODEC]);
327  if (!fmt) {
328  ast_log(LOG_ERROR, "Codec '%s' not found for sending RTP to '%s'\n",
329  opt_args[OPT_ARG_RTP_CODEC], args.destination);
330  goto failure;
331  }
332  } else {
333  fmt = derive_format_from_cap(cap);
334  if (!fmt) {
335  ast_log(LOG_ERROR, "No codec available for sending RTP to '%s'\n",
336  args.destination);
337  goto failure;
338  }
339  }
340 
342  if (!caps) {
343  goto failure;
344  }
345 
346  engine_name = S_COR(ast_test_flag(&opts, OPT_RTP_ENGINE),
347  opt_args[OPT_ARG_RTP_ENGINE], "asterisk");
348 
349  ast_sockaddr_copy(&local_address, &address);
350  if (ast_ouraddrfor(&address, &local_address)) {
351  ast_log(LOG_ERROR, "Could not get our address for sending media to '%s'\n",
352  args.destination);
353  goto failure;
354  }
355  instance = ast_rtp_instance_new(engine_name, NULL, &local_address, NULL);
356  if (!instance) {
358  "Could not create %s RTP instance for sending media to '%s'\n",
359  S_OR(engine_name, "default"), args.destination);
360  goto failure;
361  }
362 
363  chan = ast_channel_alloc(1, AST_STATE_DOWN, "", "", "", "", "", assignedids,
364  requestor, 0, "UnicastRTP/%s-%p", args.destination, instance);
365  if (!chan) {
366  ast_rtp_instance_destroy(instance);
367  goto failure;
368  }
371  ast_channel_set_fd(chan, 0, ast_rtp_instance_fd(instance, 0));
372 
374 
375  ast_format_cap_append(caps, fmt, 0);
376  ast_channel_nativeformats_set(chan, caps);
377  ast_channel_set_writeformat(chan, fmt);
379  ast_channel_set_readformat(chan, fmt);
381 
382  ast_channel_tech_pvt_set(chan, instance);
383 
384  pbx_builtin_setvar_helper(chan, "UNICASTRTP_LOCAL_ADDRESS",
385  ast_sockaddr_stringify_addr(&local_address));
386  ast_rtp_instance_get_local_address(instance, &local_address);
387  pbx_builtin_setvar_helper(chan, "UNICASTRTP_LOCAL_PORT",
388  ast_sockaddr_stringify_port(&local_address));
389 
390  ast_channel_unlock(chan);
391 
392  ao2_ref(fmt, -1);
393  ao2_ref(caps, -1);
394 
395  return chan;
396 
397 failure:
398  ao2_cleanup(fmt);
399  ao2_cleanup(caps);
400  *cause = AST_CAUSE_FAILURE;
401  return NULL;
402 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
Main Channel structure associated with a channel.
static struct ast_format * derive_format_from_cap(struct ast_format_cap *cap)
Definition: chan_rtp.c:122
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
Definition: rtp_engine.c:553
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:230
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:171
char * address
Definition: f2c.h:59
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
int ast_dns_resolve_ipv6_and_ipv4(struct ast_sockaddr *address, const char *host, const char *port)
Synchronously resolves host to an AAAA or A record.
Definition: dns_core.c:369
Definition of a media format.
Definition: format.c:43
const char * args
#define NULL
Definition: resample.c:96
Socket address structure.
Definition: netsock2.h:97
#define ast_format_cache_get(name)
Definition: format_cache.h:286
#define ast_strlen_zero(foo)
Definition: strings.h:52
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
Definition: netsock2.h:362
int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)
Get our local IP address when contacting a remote host.
Definition: acl.c:1005
#define ast_log
Definition: astobj2.c:42
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
static char host[256]
Definition: muted.c:77
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
Definition: netsock2.c:164
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:85
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static const struct ast_app_option unicast_rtp_options[128]
Definition: chan_rtp.c:266
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:2906
const char * ast_channel_uniqueid(const struct ast_channel *chan)
#define AST_CAUSE_FAILURE
Definition: causes.h:149
#define LOG_ERROR
Definition: logger.h:285
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the &#39;nonstandard&#39; argument separation process for an application.
#define ast_rtp_instance_set_remote_address(instance, address)
Set the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.h:1080
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Definition: rtp_engine.c:2192
void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the local address that we are expecting RTP on.
Definition: rtp_engine.c:643
Structure used to handle boolean flags.
Definition: utils.h:199
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:458
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2431
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
static struct ast_channel_tech unicast_rtp_tech
Definition: chan_rtp.c:68
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
static struct test_options options
struct ast_rtp_instance * ast_rtp_instance_new(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
Create a new RTP instance.
Definition: rtp_engine.c:465
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ unload_module()

static int unload_module ( void  )
static

Function called when our module is unloaded.

Definition at line 405 of file chan_rtp.c.

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

Referenced by load_module().

406 {
410 
414 
415  return 0;
416 }
static struct ast_channel_tech multicast_rtp_tech
Definition: chan_rtp.c:57
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
Definition: channel.c:570
#define NULL
Definition: resample.c:96
struct ast_format_cap * capabilities
Definition: channel.h:633
static struct ast_channel_tech unicast_rtp_tech
Definition: chan_rtp.c:68
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

Variable Documentation

◆ __mod_info

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DRIVER, .requires = "res_rtp_multicast", }
static

Definition at line 451 of file chan_rtp.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 451 of file chan_rtp.c.

◆ multicast_rtp_tech

struct ast_channel_tech multicast_rtp_tech
static

Definition at line 57 of file chan_rtp.c.

◆ unicast_rtp_options

const struct ast_app_option unicast_rtp_options[128] = { [ 'c' ] = { .flag = OPT_RTP_CODEC , .arg_index = OPT_ARG_RTP_CODEC + 1 }, [ 'e' ] = { .flag = OPT_RTP_ENGINE , .arg_index = OPT_ARG_RTP_ENGINE + 1 }, }
static

Definition at line 266 of file chan_rtp.c.

Referenced by unicast_rtp_request().

◆ unicast_rtp_tech

struct ast_channel_tech unicast_rtp_tech
static

Definition at line 68 of file chan_rtp.c.