45 #include "asterisk/multicast_rtp.h"
58 .type =
"MulticastRTP",
59 .description =
"Multicast RTP Paging Channel Driver",
70 .description =
"Unicast RTP Media Channel Driver",
82 int fdno = ast_channel_fdno(ast);
117 ast_channel_tech_pvt_set(ast, NULL);
157 if (ast_strlen_zero(data)) {
158 ast_log(LOG_ERROR,
"A multicast type and destination must be given to the 'MulticastRTP' channel\n");
164 if (ast_strlen_zero(args.type)) {
165 ast_log(LOG_ERROR,
"Type is required for the 'MulticastRTP' channel\n");
169 if (ast_strlen_zero(args.destination)) {
170 ast_log(LOG_ERROR,
"Destination is required for the 'MulticastRTP' channel\n");
173 if (!
ast_sockaddr_parse(&destination_address, args.destination, PARSE_PORT_REQUIRE)) {
174 ast_log(LOG_ERROR,
"Destination address '%s' could not be parsed\n",
180 if (!ast_strlen_zero(args.control)
182 ast_log(LOG_ERROR,
"Control address '%s' could not be parsed\n", args.control);
187 if (!mcast_options) {
193 fmt = derive_format_from_cap(cap);
196 ast_log(LOG_ERROR,
"No codec available for sending RTP to '%s'\n",
209 "Could not create '%s' multicast RTP instance for sending media to '%s'\n",
210 args.type, args.destination);
215 requestor, 0,
"MulticastRTP/%s-%p", args.destination, instance);
223 ast_channel_tech_set(chan, &multicast_rtp_tech);
226 ast_channel_nativeformats_set(chan, caps);
227 ast_channel_set_writeformat(chan, fmt);
228 ast_channel_set_rawwriteformat(chan, fmt);
229 ast_channel_set_readformat(chan, fmt);
230 ast_channel_set_rawreadformat(chan, fmt);
232 ast_channel_tech_pvt_set(chan, instance);
234 ast_channel_unlock(chan);
246 *cause = AST_CAUSE_FAILURE;
251 OPT_RTP_CODEC = (1 << 0),
252 OPT_RTP_ENGINE = (1 << 1),
253 OPT_RTP_GLUE = (1 << 2),
273 .
type =
"CHAN_RTP_GLUE",
286 const char *engine_name;
292 char *opt_args[OPT_ARG_ARRAY_SIZE];
294 if (ast_strlen_zero(data)) {
295 ast_log(LOG_ERROR,
"Destination is required for the 'UnicastRTP' channel\n");
301 if (ast_strlen_zero(args.destination)) {
302 ast_log(LOG_ERROR,
"Destination is required for the 'UnicastRTP' channel\n");
313 ast_log(LOG_ERROR,
"Unable to parse destination '%s' into host and port\n", args.destination);
319 ast_log(LOG_ERROR,
"Unable to resolve host '%s'\n", host);
324 if (!ast_strlen_zero(args.options)
327 ast_log(LOG_ERROR,
"'UnicastRTP' channel options '%s' parse error\n",
332 if (ast_test_flag(&opts, OPT_RTP_CODEC)
333 && !ast_strlen_zero(opt_args[OPT_ARG_RTP_CODEC])) {
336 ast_log(LOG_ERROR,
"Codec '%s' not found for sending RTP to '%s'\n",
337 opt_args[OPT_ARG_RTP_CODEC], args.destination);
341 fmt = derive_format_from_cap(cap);
343 ast_log(LOG_ERROR,
"No codec available for sending RTP to '%s'\n",
354 engine_name =
S_COR(ast_test_flag(&opts, OPT_RTP_ENGINE),
355 opt_args[OPT_ARG_RTP_ENGINE],
"asterisk");
359 ast_log(LOG_ERROR,
"Could not get our address for sending media to '%s'\n",
366 "Could not create %s RTP instance for sending media to '%s'\n",
367 S_OR(engine_name,
"default"), args.destination);
372 requestor, 0,
"UnicastRTP/%s-%p", args.destination, instance);
381 ast_channel_tech_set(chan, &unicast_rtp_tech);
383 if (ast_test_flag(&opts, OPT_RTP_GLUE)) {
385 if ((datastore = ast_datastore_alloc(&chan_rtp_datastore_info, NULL))) {
391 ast_channel_nativeformats_set(chan, caps);
392 ast_channel_set_writeformat(chan, fmt);
393 ast_channel_set_rawwriteformat(chan, fmt);
394 ast_channel_set_readformat(chan, fmt);
395 ast_channel_set_rawreadformat(chan, fmt);
397 ast_channel_tech_pvt_set(chan, instance);
405 ast_channel_unlock(chan);
415 *cause = AST_CAUSE_FAILURE;
422 SCOPE_ENTER(1,
"%s Native formats %s\n", ast_channel_name(chan),
456 *instance = rtp_instance;
467 .
type =
"UnicastRTP",
497 ast_rtp_glue_register(&unicast_rtp_glue);
501 ast_log(LOG_ERROR,
"Unable to register channel class 'MulticastRTP'\n");
512 ast_log(LOG_ERROR,
"Unable to register channel class 'UnicastRTP'\n");
520 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"RTP Media Channel",
521 .support_level = AST_MODULE_SUPPORT_CORE,
525 .requires =
"res_rtp_multicast",
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
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...
struct ast_multicast_rtp_options * ast_multicast_rtp_create_options(const char *type, const char *options)
Create multicast RTP options.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
static enum ast_rtp_glue_result chan_rtp_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
Function called by RTP engine to get local audio RTP peer.
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
static enum ast_rtp_glue_result chan_rtp_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
Function called by RTP engine to get local audio RTP peer.
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
static int rtp_hangup(struct ast_channel *ast)
Function called when we should hang the channel up.
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
static int unload_module(void)
Function called when our module is unloaded.
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
static int chan_rtp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *tpeer, const struct ast_format_cap *cap, int nat_active)
Function called by RTP engine to change where the remote party should send media. ...
Structure to pass both assignedid values to channel drivers.
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.
Structure for a data store type.
void ast_multicast_rtp_free_options(struct ast_multicast_rtp_options *mcast_options)
Free multicast RTP options.
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 ...
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Socket address structure.
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)
Get our local IP address when contacting a remote host.
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Access Control of various sorts.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
static int rtp_call(struct ast_channel *ast, const char *dest, int timeout)
Function called when we should actually call the destination.
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
static int rtp_write(struct ast_channel *ast, struct ast_frame *f)
Function called when we should write a frame to the channel.
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.
static struct ast_rtp_glue unicast_rtp_glue
Local glue for interacting with the RTP engine core.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' 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.
static int load_module(void)
Function called when our module is loaded.
struct ast_format * ast_multicast_rtp_options_get_format(struct ast_multicast_rtp_options *mcast_options)
Get format specified in multicast options.
struct ast_format_cap * capabilities
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Module has failed to load, may be in an inconsistent state.
static struct ast_frame * rtp_read(struct ast_channel *ast)
Function called when we should read a frame from the channel.
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.
Structure used to handle boolean flags.
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
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...
struct ast_frame ast_null_frame
static void chan_rtp_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
Function called by RTP engine to get peer capabilities.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
Unregister RTP glue.
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)
Function called when we should prepare to call the unicast destination.
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
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.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Pluggable RTP Architecture.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
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)
Function called when we should prepare to call the multicast destination.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ast_frame * ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
Receive a frame over RTP.
#define AST_APP_ARG(name)
Define an application argument.