60 #define LINKSYS_MCAST_STARTCMD 6 63 #define LINKSYS_MCAST_STOPCMD 7 98 struct timeval txcore;
102 #define MAX_TIMESTAMP_SKEW 640 146 mcast_options =
ast_calloc(1,
sizeof(*mcast_options)
148 + strlen(
S_OR(options,
"")) + 2);
149 if (!mcast_options) {
153 pos = mcast_options->
buf;
157 mcast_options->
type = pos;
158 pos += strlen(type) + 1;
161 strcpy(pos, options);
172 return mcast_options;
209 if (!strcasecmp(type,
"basic")) {
211 }
else if (!strcasecmp(type,
"linksys")) {
221 static void set_ttl(
int sock,
const char *ttl_str)
229 ast_debug(3,
"Setting multicast TTL to %s\n", ttl_str);
231 if (sscanf(ttl_str,
"%30d", &ttl) < 1) {
236 if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
sizeof(ttl)) < 0) {
238 ttl_str, strerror(
errno));
242 static void set_loop(
int sock,
const char *loop_str)
250 ast_debug(3,
"Setting multicast loop to %s\n", loop_str);
252 if (sscanf(loop_str,
"%30hhu", &loop) < 1) {
257 if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, &loop,
sizeof(loop)) < 0) {
259 loop_str, strerror(
errno));
263 static void set_if(
int sock,
const char *if_str)
265 struct in_addr iface;
271 ast_debug(3,
"Setting multicast if to %s\n", if_str);
277 if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &iface,
sizeof(iface)) < 0) {
279 if_str, strerror(
errno));
289 if (!(multicast =
ast_calloc(1,
sizeof(*multicast)))) {
298 if ((multicast->
socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
344 return (
unsigned int) ms;
351 .command = htonl(command),
367 "remote address.\n");
375 ast_sendto(multicast->
socket, &control_packet,
sizeof(control_packet), 0, &control_address);
376 ast_sendto(multicast->
socket, &control_packet,
sizeof(control_packet), 0, &control_address);
417 unsigned char *rtpheader;
420 int hdrlen = 12, mark = 0;
427 multicast->
lastts = frame->
ts * rate;
435 int delta =
abs((
int) multicast->
lastts - pred);
439 ast_debug(3,
"Difference is %d, ms is %u\n", delta, ms);
446 rtpheader = (
unsigned char *)(frame->
data.
ptr - hdrlen);
453 multicast->
seqno = 0xFFFF & (multicast->
seqno + 1);
522 if (frame->
offset < hdrlen) {
#define MAX_TIMESTAMP_SKEW
struct ast_multicast_rtp_options * ast_multicast_rtp_create_options(const char *type, const char *options)
Create multicast RTP options.
static int multicast_send_control_packet(struct ast_rtp_instance *instance, struct multicast_rtp *multicast, int command)
Helper function which populates a control packet with useful information and sends it...
#define ast_frdup(fr)
Copies a frame.
Structure for a Linksys control packet.
ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr)
Wrapper around sendto(2) that uses ast_sockaddr.
static int unload_module(void)
Asterisk locking-related definitions:
multicast_type
Type of paging to do.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_rtp_engine_register(engine)
static void set_if(int sock, const char *if_str)
#define ast_smoother_feed(s, f)
struct ast_smoother * ast_smoother_new(int bytes)
#define ast_test_flag(p, flag)
struct ast_rtp_codecs * ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance)
Get the codecs structure of an RTP instance.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
static unsigned int calc_txstamp(struct multicast_rtp *rtp, struct timeval *delivery)
static void set_ttl(int sock, const char *ttl_str)
static void put_unaligned_uint32(void *p, unsigned int datum)
uint32_t ast_sockaddr_ipv4(const struct ast_sockaddr *addr)
Get an IPv4 address of an ast_sockaddr.
void ast_multicast_rtp_free_options(struct ast_multicast_rtp_options *mcast_options)
Free multicast RTP options.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Socket address structure.
Asterisk internal frame definitions.
int ast_rtp_codecs_payload_code_tx(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code...
unsigned int ast_rtp_codecs_get_framing(struct ast_rtp_codecs *codecs)
Get the framing used for a set of codecs.
struct ast_frame_subclass subclass
#define ast_strlen_zero(foo)
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized, or having a 0 length.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Configuration File Parser.
void ast_smoother_free(struct ast_smoother *s)
Structure for a multicast paging instance.
static const struct ast_app_option multicast_rtp_options[128]
#define ast_debug(level,...)
Log a DEBUG message.
Handle unaligned data access.
char * opt_args[OPT_ARG_ARRAY_SIZE]
General Asterisk PBX channel definitions.
int ast_rtp_engine_unregister(struct ast_rtp_engine *engine)
Unregister an RTP engine.
void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data)
Set the data portion of an RTP instance.
struct ast_smoother * smoother
Access Control of various sorts.
#define AST_SMOOTHER_FLAG_FORCED
Asterisk internal frame definitions.
long int ast_random(void)
static void set_loop(int sock, const char *loop_str)
#define LINKSYS_MCAST_STARTCMD
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.
Core PBX routines and definitions.
static int multicast_rtp_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Function called to broadcast some audio on a multicast instance.
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
static int set_type(struct multicast_rtp *multicast, const char *type)
#define ast_smoother_feed_be(s, f)
static struct ast_rtp_engine multicast_rtp_engine
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
static int multicast_rtp_activate(struct ast_rtp_instance *instance)
Function called to indicate that audio is now going to flow.
#define LINKSYS_MCAST_STOPCMD
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
struct ast_format * ast_multicast_rtp_options_get_format(struct ast_multicast_rtp_options *mcast_options)
Get format specified in multicast options.
static int rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame *frame, int codec)
#define ast_calloc(num, len)
A wrapper for calloc()
void * ast_rtp_instance_get_data(struct ast_rtp_instance *instance)
Get the data portion of an RTP instance.
static struct ast_frame * multicast_rtp_read(struct ast_rtp_instance *instance, int rtcp)
Function called to read from a multicast instance.
Module has failed to load, may be in an inconsistent state.
static int rtp_get_rate(struct ast_format *format)
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_smoother_test_flag(struct ast_smoother *s, int flag)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
struct ast_frame ast_null_frame
#define AST_SMOOTHER_FLAG_BE
static int multicast_rtp_destroy(struct ast_rtp_instance *instance)
Function called to destroy a multicast instance.
void ast_smoother_set_flags(struct ast_smoother *smoother, int flags)
static int load_module(void)
Standard Command Line Interface.
struct ast_frame * ast_smoother_read(struct ast_smoother *s)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Data structure associated with a single frame of data.
static int multicast_rtp_new(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *addr, void *data)
Function called to create a new multicast instance.
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
Pluggable RTP Architecture.
Asterisk module definitions.
static snd_pcm_format_t format
#define ast_rtp_instance_get_remote_address(instance, address)
Get the address of the remote endpoint that we are sending RTP to.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int inet_aton(const char *cp, struct in_addr *pin)
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.