Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
res_rtp_multicast.c File Reference

Multicast RTP Engine. More...

#include "asterisk.h"
#include <sys/time.h>
#include <signal.h>
#include <fcntl.h>
#include <math.h>
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/acl.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/manager.h"
#include "asterisk/unaligned.h"
#include "asterisk/module.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/format_cache.h"
#include "asterisk/multicast_rtp.h"
#include "asterisk/app.h"
#include "asterisk/smoother.h"

Go to the source code of this file.

Data Structures

struct  ast_multicast_rtp_options
 
struct  multicast_control_packet
 Structure for a Linksys control packet. More...
 
struct  multicast_rtp
 Structure for a multicast paging instance. More...
 

Macros

#define LINKSYS_MCAST_STARTCMD   6
 
#define LINKSYS_MCAST_STOPCMD   7
 
#define MAX_TIMESTAMP_SKEW   640
 

Enumerations

enum  { OPT_CODEC = (1 << 0), OPT_LOOP = (1 << 1), OPT_TTL = (1 << 2), OPT_IF = (1 << 3) }
 
enum  {
  OPT_ARG_CODEC = 0, OPT_ARG_LOOP, OPT_ARG_TTL, OPT_ARG_IF,
  OPT_ARG_ARRAY_SIZE
}
 
enum  multicast_type { MULTICAST_TYPE_UNSPECIFIED = 0, MULTICAST_TYPE_BASIC, MULTICAST_TYPE_LINKSYS }
 Type of paging to do. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
struct ast_multicast_rtp_optionsast_multicast_rtp_create_options (const char *type, const char *options)
 Create multicast RTP options. More...
 
void ast_multicast_rtp_free_options (struct ast_multicast_rtp_options *mcast_options)
 Free multicast RTP options. More...
 
struct ast_formatast_multicast_rtp_options_get_format (struct ast_multicast_rtp_options *mcast_options)
 Get format specified in multicast options. More...
 
static unsigned int calc_txstamp (struct multicast_rtp *rtp, struct timeval *delivery)
 
static int load_module (void)
 
static int multicast_rtp_activate (struct ast_rtp_instance *instance)
 Function called to indicate that audio is now going to flow.
 
static int multicast_rtp_destroy (struct ast_rtp_instance *instance)
 Function called to destroy a multicast instance.
 
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.
 
static struct ast_framemulticast_rtp_read (struct ast_rtp_instance *instance, int rtcp)
 Function called to read from a multicast instance.
 
static int multicast_rtp_write (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Function called to broadcast some audio on a multicast instance.
 
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.
 
static int rtp_get_rate (struct ast_format *format)
 
static int rtp_raw_write (struct ast_rtp_instance *instance, struct ast_frame *frame, int codec)
 
static void set_if (int sock, const char *if_str)
 
static void set_loop (int sock, const char *loop_str)
 
static void set_ttl (int sock, const char *ttl_str)
 
static int set_type (struct multicast_rtp *multicast, const char *type)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Multicast RTP Engine" , .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_DEPEND, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_rtp_engine multicast_rtp_engine
 
static const struct ast_app_option multicast_rtp_options [128] = { [ 'c' ] = { .flag = OPT_CODEC , .arg_index = OPT_ARG_CODEC + 1 }, [ 'l' ] = { .flag = OPT_LOOP , .arg_index = OPT_ARG_LOOP + 1 }, [ 't' ] = { .flag = OPT_TTL , .arg_index = OPT_ARG_TTL + 1 }, [ 'i' ] = { .flag = OPT_IF , .arg_index = OPT_ARG_IF + 1 }, }
 

Detailed Description

Multicast RTP Engine.

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

Definition in file res_rtp_multicast.c.

Macro Definition Documentation

#define LINKSYS_MCAST_STARTCMD   6

Command value used for Linksys paging to indicate we are starting

Definition at line 60 of file res_rtp_multicast.c.

Referenced by multicast_rtp_activate().

#define LINKSYS_MCAST_STOPCMD   7

Command value used for Linksys paging to indicate we are stopping

Definition at line 63 of file res_rtp_multicast.c.

Referenced by multicast_rtp_destroy().

Enumeration Type Documentation

Type of paging to do.

Enumerator
MULTICAST_TYPE_UNSPECIFIED 

Type has not been set yet

MULTICAST_TYPE_BASIC 

Simple multicast enabled client/receiver paging like Snom and Barix uses

MULTICAST_TYPE_LINKSYS 

More advanced Linksys type paging which requires a start and stop packet

Definition at line 66 of file res_rtp_multicast.c.

66  {
67  /*! Type has not been set yet */
69  /*! Simple multicast enabled client/receiver paging like Snom and Barix uses */
71  /*! More advanced Linksys type paging which requires a start and stop packet */
73 };

Function Documentation

struct ast_multicast_rtp_options* ast_multicast_rtp_create_options ( const char *  type,
const char *  options 
)

Create multicast RTP options.

These are passed to the multicast RTP engine on its creation.

Parameters
typeThe type of multicast RTP, either "basic" or "linksys"
optionsMiscellaneous options
Return values
NULLFailure
non-NULLsuccess

Definition at line 140 of file res_rtp_multicast.c.

References ast_app_parse_options(), ast_calloc, ast_multicast_rtp_free_options(), ast_multicast_rtp_options::buf, and S_OR.

Referenced by multicast_rtp_request().

142 {
143  struct ast_multicast_rtp_options *mcast_options;
144  char *pos;
145 
146  mcast_options = ast_calloc(1, sizeof(*mcast_options)
147  + strlen(type)
148  + strlen(S_OR(options, "")) + 2);
149  if (!mcast_options) {
150  return NULL;
151  }
152 
153  pos = mcast_options->buf;
154 
155  /* Safe */
156  strcpy(pos, type);
157  mcast_options->type = pos;
158  pos += strlen(type) + 1;
159 
160  if (!ast_strlen_zero(options)) {
161  strcpy(pos, options); /* Safe */
162  }
163  mcast_options->options = pos;
164 
165  if (ast_app_parse_options(multicast_rtp_options, &mcast_options->opts,
166  mcast_options->opt_args, mcast_options->options)) {
167  ast_log(LOG_WARNING, "Error parsing multicast RTP options\n");
168  ast_multicast_rtp_free_options(mcast_options);
169  return NULL;
170  }
171 
172  return mcast_options;
173 }
void ast_multicast_rtp_free_options(struct ast_multicast_rtp_options *mcast_options)
Free multicast RTP options.
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:3066
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
void ast_multicast_rtp_free_options ( struct ast_multicast_rtp_options mcast_options)

Free multicast RTP options.

This function is NULL-tolerant

Parameters
mcast_optionsOptions to free

Definition at line 175 of file res_rtp_multicast.c.

Referenced by ast_multicast_rtp_create_options(), and multicast_rtp_request().

176 {
177  ast_free(mcast_options);
178 }
struct ast_format* ast_multicast_rtp_options_get_format ( struct ast_multicast_rtp_options mcast_options)

Get format specified in multicast options.

Multicast options allow for a format to be selected. This function accesses the selected format and creates an ast_format structure for it.

Parameters
mcast_optionsThe options where a codec was specified
Return values
NULLNo format specified in the options
non-NULLThe format to use for communication

Definition at line 180 of file res_rtp_multicast.c.

References ast_format_cache_get.

Referenced by multicast_rtp_request().

181 {
182  if (ast_test_flag(&mcast_options->opts, OPT_CODEC)
183  && !ast_strlen_zero(mcast_options->opt_args[OPT_ARG_CODEC])) {
184  return ast_format_cache_get(mcast_options->opt_args[OPT_ARG_CODEC]);
185  }
186 
187  return NULL;
188 }
#define ast_format_cache_get(name)
Retrieve a named format from the cache.
Definition: format_cache.h:278