43#define MODULE_DESCRIPTION "AudioSocket support functions for Asterisk"
45#define MAX_CONNECT_TIMEOUT_MSEC 2000
61 struct pollfd pfds[1];
65 reslen =
sizeof(conresult);
67 pfds[0].fd = netsockfd;
68 pfds[0].events = POLLOUT;
74 "out after MAX_CONNECT_TIMEOUT_MSEC (%d) milliseconds.\n",
85 if (getsockopt(pfds[0].fd, SOL_SOCKET, SO_ERROR, &conresult, &reslen) < 0) {
104 int num_addrs = 0, i = 0;
120 "requires a valid hostname and port\n", server);
125 for (i = 0; i < num_addrs; i++) {
172 if (i == num_addrs) {
192 if (uuid_parse(
id, uu)) {
200 memcpy(
buf + 3, uu, 16);
202 if (write(svc,
buf, 3 + 16) != 3 + 16) {
218 uint8_t
buf[3 + datalen];
219 uint16_t *length = (uint16_t *) &
buf[1];
226 *length = htons(datalen);
239 if (write(svc,
buf, 3 + datalen) != 3 + datalen) {
256 int i = 0, n = 0, ret = 0;
260 .src =
"AudioSocket",
264 uint8_t *kind = &
header[0];
265 uint16_t *length = (uint16_t *) &
header[1];
272 n = read(svc, &
header, 3);
287 ast_log(
LOG_ERROR,
"Received AudioSocket message other than hangup or audio, refer to protocol specification for valid message types\n");
292 *length = ntohs(*length);
294 ast_log(
LOG_ERROR,
"Invalid message length received from AudioSocket server. \n");
307 while (i < *length) {
308 n = read(svc,
data + i, *length - i);
337 ast_verb(5,
"Loading AudioSocket Support module\n");
343 ast_verb(5,
"Unloading AudioSocket Support module\n");
Asterisk main include file. File version handling, generic pbx functions.
#define ast_malloc(len)
A wrapper for malloc()
static int hangup(void *data)
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Generic File Format Support. Should be included by clients of the file handling routines....
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
#define ast_verb(level,...)
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_CHANNEL_DEPEND
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
int ast_connect(int sockfd, const struct ast_sockaddr *addr)
Wrapper around connect(2) that uses struct ast_sockaddr.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
#define ast_poll(a, b, c)
const int ast_audiosocket_init(const int svc, const char *id)
Send the initial message to an AudioSocket server.
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_frame * ast_audiosocket_receive_frame(const int svc)
Receive an Asterisk frame from an AudioSocket server.
struct ast_frame * ast_audiosocket_receive_frame_with_hangup(const int svc, int *const hangup)
Receive an Asterisk frame from an AudioSocket server.
const int ast_audiosocket_connect(const char *server, struct ast_channel *chan)
Send the initial message to an AudioSocket server.
#define MAX_CONNECT_TIMEOUT_MSEC
static int load_module(void)
static int unload_module(void)
static int handle_audiosocket_connection(const char *server, const struct ast_sockaddr addr, const int netsockfd)
AudioSocket support functions.
@ AST_AUDIOSOCKET_KIND_AUDIO
Messages contains audio data, direction: Sent and received.
@ AST_AUDIOSOCKET_KIND_HANGUP
Message indicates the channel should be hung up, direction: Sent only.
@ AST_AUDIOSOCKET_KIND_UUID
Message contains the connection's UUID, direction: Received only.
@ AST_AUDIOSOCKET_KIND_DTMF
Message contains a DTMF digit, direction: Received only.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Main Channel structure associated with a channel.
Data structure associated with a single frame of data.
union ast_frame::@228 data
struct ast_frame_subclass subclass
enum ast_frame_type frametype
Socket address structure.
struct sockaddr_storage ss
#define ast_socket_nonblock(domain, type, protocol)
Create a non-blocking socket.
Universally unique identifier support.