34 #include <uuid/uuid.h>
63 .type =
"AudioSocket",
64 .description =
"AudioSocket Channel Driver",
78 instance = ast_channel_tech_pvt(ast);
79 if (instance == NULL || instance->svc < FD_OUTPUT) {
91 instance = ast_channel_tech_pvt(ast);
92 if (instance == NULL || instance->svc < 1) {
114 instance = ast_channel_tech_pvt(ast);
115 if (instance != NULL && instance->svc > 0) {
116 close(instance->svc);
119 ast_channel_tech_pvt_set(ast, NULL);
126 OPT_AUDIOSOCKET_CODEC = (1 << 0),
130 OPT_ARG_AUDIOSOCKET_CODEC = (1 << 0),
157 char *opt_args[OPT_ARG_ARRAY_SIZE];
159 if (ast_strlen_zero(data)) {
160 ast_log(LOG_ERROR,
"Destination is required for the 'AudioSocket' channel\n");
166 if (ast_strlen_zero(args.destination)) {
167 ast_log(LOG_ERROR,
"Destination is required for the 'AudioSocket' channel\n");
171 (&address, args.destination, PARSE_PORT_REQUIRE, AST_AF_UNSPEC)) {
172 ast_log(LOG_ERROR,
"Destination '%s' could not be parsed\n", args.destination);
176 if (ast_strlen_zero(args.idStr)) {
177 ast_log(LOG_ERROR,
"UUID is required for the 'AudioSocket' channel\n");
180 if (uuid_parse(args.idStr, uu)) {
181 ast_log(LOG_ERROR,
"Failed to parse UUID '%s'\n", args.idStr);
185 if (!ast_strlen_zero(args.options)
188 ast_log(LOG_ERROR,
"'AudioSocket' channel options '%s' parse error\n",
193 if (ast_test_flag(&opts, OPT_AUDIOSOCKET_CODEC)
194 && !ast_strlen_zero(opt_args[OPT_ARG_AUDIOSOCKET_CODEC])) {
197 ast_log(LOG_ERROR,
"Codec '%s' not found for AudioSocket connection to '%s'\n",
198 opt_args[OPT_ARG_AUDIOSOCKET_CODEC], args.destination);
204 ast_log(LOG_ERROR,
"No codec available for AudioSocket connection to '%s'\n",
217 ast_log(LOG_ERROR,
"Failed to allocate AudioSocket channel pvt\n");
228 requestor, 0,
"AudioSocket/%s-%s", args.destination, args.idStr);
234 ast_channel_tech_set(chan, &audiosocket_channel_tech);
237 ast_channel_nativeformats_set(chan, caps);
238 ast_channel_set_writeformat(chan, fmt);
239 ast_channel_set_rawwriteformat(chan, fmt);
240 ast_channel_set_readformat(chan, fmt);
241 ast_channel_set_rawreadformat(chan, fmt);
243 ast_channel_tech_pvt_set(chan, instance);
248 ast_channel_unlock(chan);
255 *cause = AST_CAUSE_FAILURE;
258 if (instance != NULL) {
286 ast_log(LOG_ERROR,
"Unable to register channel class AudioSocket");
295 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"AudioSocket Channel",
296 .support_level = AST_MODULE_SUPPORT_EXTENDED,
300 .requires =
"res_audiosocket",
Main Channel structure associated with a channel.
static struct ast_channel * audiosocket_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.
Asterisk main include file. File version handling, generic pbx functions.
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
static int audiosocket_call(struct ast_channel *ast, const char *dest, int timeout)
Function called when we should actually call the destination.
Structure to pass both assignedid values to channel drivers.
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 ...
Socket address structure.
const int ast_audiosocket_connect(const char *server, struct ast_channel *chan)
Send the initial message to an AudioSocket server.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
const int ast_audiosocket_init(const int svc, const char *id)
Send the initial message to an AudioSocket server.
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.
AudioSocket support functions.
int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr, const char *name, int flag, int family)
Return the first entry from ast_sockaddr_resolve filtered by address family.
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.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
static int audiosocket_write(struct ast_channel *ast, struct ast_frame *f)
Function called when we should write a frame to the channel.
#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.
const int ast_audiosocket_send_frame(const int svc, const struct ast_frame *f)
Send an Asterisk audio frame to an AudioSocket server.
struct ast_format_cap * capabilities
#define ast_calloc(num, len)
A wrapper for calloc()
static int audiosocket_hangup(struct ast_channel *ast)
Function called when we should hang the channel up.
Module has failed to load, may be in an inconsistent state.
Structure used to handle boolean flags.
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_audiosocket_receive_frame(const int svc)
Receive an Asterisk frame from an AudioSocket server.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
static struct ast_frame * audiosocket_read(struct ast_channel *ast)
Function called when we should read a frame from the channel.
static int load_module(void)
Function called when our module is loaded.
static int unload_module(void)
Function called when our module is unloaded.
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
#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...
#define AST_APP_ARG(name)
Define an application argument.