git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@416 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-01-20 00:40:29 +00:00
parent e528c4df33
commit 42383b1f15
12 changed files with 468 additions and 471 deletions

View File

@ -31,7 +31,8 @@
*/
#include <switch.h>
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
char *err = NULL;
switch_event *event;
@ -47,7 +48,7 @@ int main(int argc, char *argv[]) {
}
}
if(err) {
if (err) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error: %s", err);
exit(-1);
}
@ -75,5 +76,3 @@ int main(int argc, char *argv[]) {
return 0;
}

View File

@ -41,7 +41,8 @@ SWITCH_DECLARE(switch_status) switch_buffer_create(switch_memory_pool *pool, swi
{
switch_buffer *new_buffer;
if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer))) && (new_buffer->data = switch_core_alloc(pool, max_len))) {
if ((new_buffer = switch_core_alloc(pool, sizeof(switch_buffer)))
&& (new_buffer->data = switch_core_alloc(pool, max_len))) {
new_buffer->datalen = max_len;
*buffer = new_buffer;
return SWITCH_STATUS_SUCCESS;
@ -54,7 +55,7 @@ SWITCH_DECLARE(int) switch_buffer_len(switch_buffer *buffer)
assert(buffer != NULL);
return (int)buffer->datalen;
return (int) buffer->datalen;
}
@ -63,14 +64,14 @@ SWITCH_DECLARE(int) switch_buffer_freespace(switch_buffer *buffer)
{
assert(buffer != NULL);
return (int)(buffer->datalen - buffer->used);
return (int) (buffer->datalen - buffer->used);
}
SWITCH_DECLARE(int) switch_buffer_inuse(switch_buffer *buffer)
{
assert(buffer != NULL);
return (int)buffer->used;
return (int) buffer->used;
}
SWITCH_DECLARE(int) switch_buffer_toss(switch_buffer *buffer, size_t datalen)
@ -91,7 +92,7 @@ SWITCH_DECLARE(int) switch_buffer_toss(switch_buffer *buffer, size_t datalen)
memmove(buffer->data, buffer->data + reading, buffer->datalen - reading);
buffer->used -= datalen;
return (int)buffer->datalen;
return (int) buffer->datalen;
}
SWITCH_DECLARE(int) switch_buffer_read(switch_buffer *buffer, void *data, size_t datalen)
@ -115,7 +116,7 @@ SWITCH_DECLARE(int) switch_buffer_read(switch_buffer *buffer, void *data, size_t
memmove(buffer->data, buffer->data + reading, buffer->datalen - reading);
buffer->used -= reading;
//printf("o %d = %d\n", reading, buffer->used);
return (int)reading;
return (int) reading;
}
SWITCH_DECLARE(int) switch_buffer_write(switch_buffer *buffer, void *data, size_t datalen)
@ -135,6 +136,5 @@ SWITCH_DECLARE(int) switch_buffer_write(switch_buffer *buffer, void *data, size_
buffer->used += datalen;
}
//printf("i %d = %d\n", datalen, buffer->used);
return (int)buffer->used;
return (int) buffer->used;
}

View File

@ -36,9 +36,7 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_se
char *caller_id_name,
char *caller_id_number,
char *network_addr,
char *ani,
char *ani2,
char *destination_number)
char *ani, char *ani2, char *destination_number)
{
@ -75,8 +73,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_
return profile;
}
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix, switch_event *event)
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix,
switch_event *event)
{
char header_name[1024];
@ -112,9 +110,7 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile
}
SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_core_session *session,
char *extension_name,
char *extension_number
)
char *extension_name, char *extension_number)
{
switch_caller_extension *caller_extension = NULL;
@ -130,8 +126,7 @@ SWITCH_DECLARE(switch_caller_extension *) switch_caller_extension_new(switch_cor
SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session *session,
switch_caller_extension *caller_extension,
char *application_name,
char *application_data)
char *application_name, char *application_data)
{
switch_caller_application *caller_application = NULL;
@ -142,7 +137,7 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session
caller_application->application_data = switch_core_session_strdup(session, application_data);
if (!caller_extension->applications) {
caller_extension->applications = caller_application;
} else if(caller_extension->last_application) {
} else if (caller_extension->last_application) {
caller_extension->last_application->next = caller_application;
}
@ -151,6 +146,3 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session
}
}

View File

@ -71,7 +71,8 @@ SWITCH_DECLARE(switch_status) switch_channel_alloc(switch_channel **channel, swi
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *channel, int freq, int bits, int channels, int ms, int kbps)
SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode(switch_channel *channel, int freq, int bits, int channels,
int ms, int kbps)
{
assert(channel != NULL);
@ -86,7 +87,8 @@ SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *chann
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode (switch_channel *channel, int *freq, int *bits, int *channels, int *ms, int *kbps)
SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode(switch_channel *channel, int *freq, int *bits, int *channels,
int *ms, int *kbps)
{
if (freq) {
*freq = channel->freq;
@ -128,7 +130,7 @@ SWITCH_DECLARE(switch_status) switch_channel_queue_dtmf(switch_channel *channel,
assert(channel != NULL);
switch_mutex_lock(channel->dtmf_mutex);
if (switch_buffer_inuse(channel->dtmf_buffer) + strlen(dtmf) > (size_t)switch_buffer_len(channel->dtmf_buffer)) {
if (switch_buffer_inuse(channel->dtmf_buffer) + strlen(dtmf) > (size_t) switch_buffer_len(channel->dtmf_buffer)) {
switch_buffer_toss(channel->dtmf_buffer, strlen(dtmf));
}
@ -164,8 +166,7 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d
SWITCH_DECLARE(switch_status) switch_channel_init(switch_channel *channel,
switch_core_session *session,
switch_channel_state state,
switch_channel_flag flags)
switch_channel_state state, switch_channel_flag flags)
{
assert(channel != NULL);
channel->state = state;
@ -277,115 +278,117 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch
}
/* STUB for more dev
case CS_INIT:
switch(state) {
case CS_INIT:
switch(state) {
case CS_NEW:
case CS_INIT:
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
case CS_DONE:
default:
break;
}
break;
*/
switch (last_state) {
case CS_NEW:
switch (state) {
default:
ok++;
break;
}
break;
case CS_INIT:
switch (state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_LOOPBACK:
switch (state) {
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_TRANSMIT:
switch (state) {
case CS_LOOPBACK:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_RING:
switch (state) {
case CS_LOOPBACK:
case CS_EXECUTE:
case CS_HANGUP:
case CS_TRANSMIT:
ok++;
default:
break;
}
break;
case CS_EXECUTE:
switch (state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_HANGUP:
case CS_DONE:
switch (state) {
case CS_DONE:
ok++;
default:
break;
}
break;
default:
break;
}
break;
*/
switch(last_state) {
case CS_NEW:
switch(state) {
default:
ok++;
break;
}
break;
case CS_INIT:
switch(state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_LOOPBACK:
switch(state) {
case CS_TRANSMIT:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_TRANSMIT:
switch(state) {
case CS_LOOPBACK:
case CS_RING:
case CS_EXECUTE:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_RING:
switch(state) {
case CS_LOOPBACK:
case CS_EXECUTE:
case CS_HANGUP:
case CS_TRANSMIT:
ok++;
default:
break;
}
break;
case CS_EXECUTE:
switch(state) {
case CS_LOOPBACK:
case CS_TRANSMIT:
case CS_RING:
case CS_HANGUP:
ok++;
default:
break;
}
break;
case CS_HANGUP:
switch(state) {
case CS_DONE:
ok++;
default:
break;
}
break;
default:
break;
break;
}
if (ok) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s State Change %s -> %s\n", channel->name,
state_names[last_state], state_names[state]);
channel->state = state;
switch_core_session_signal_state_change(channel->session);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Invalid State Change %s -> %s\n", channel->name,
state_names[last_state], state_names[state]);
//we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee!
if (channel->state < CS_HANGUP) {
@ -399,7 +402,7 @@ default:
SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, switch_event *event)
{
switch_caller_profile *caller_profile, *originator_caller_profile, *originatee_caller_profile;
switch_hash_index_t* hi;
switch_hash_index_t *hi;
void *val;
const void *var;
@ -407,7 +410,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
originator_caller_profile = switch_channel_get_originator_caller_profile(channel);
originatee_caller_profile = switch_channel_get_originatee_caller_profile(channel);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State",
(char *) switch_channel_state_name(channel->state));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
@ -428,7 +432,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit
}
/* Index Variables */
for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi; hi = switch_hash_next(hi)) {
for (hi = switch_hash_first(switch_core_session_get_pool(channel->session), channel->variables); hi;
hi = switch_hash_next(hi)) {
char buf[1024];
switch_event_subclass *subclass;
switch_hash_this(hi, &var, NULL, &val);
@ -453,13 +458,15 @@ SWITCH_DECLARE(switch_caller_profile *) switch_channel_get_caller_profile(switch
return channel->caller_profile;
}
SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile)
SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel *channel,
switch_caller_profile *caller_profile)
{
assert(channel != NULL);
channel->originator_caller_profile = caller_profile;
}
SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel *channel, switch_caller_profile *caller_profile)
SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel *channel,
switch_caller_profile *caller_profile)
{
assert(channel != NULL);
channel->originatee_caller_profile = caller_profile;
@ -477,7 +484,8 @@ SWITCH_DECLARE(switch_caller_profile *) switch_channel_get_originatee_caller_pro
return channel->originatee_caller_profile;
}
SWITCH_DECLARE(void) switch_channel_set_event_handlers(switch_channel *channel, const struct switch_event_handler_table *event_handlers)
SWITCH_DECLARE(void) switch_channel_set_event_handlers(switch_channel *channel,
const struct switch_event_handler_table *event_handlers)
{
assert(channel != NULL);
channel->event_handlers = event_handlers;
@ -489,7 +497,8 @@ SWITCH_DECLARE(const struct switch_event_handler_table *) switch_channel_get_eve
return channel->event_handlers;
}
SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel *channel, switch_caller_extension *caller_extension)
SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel *channel,
switch_caller_extension *caller_extension)
{
assert(channel != NULL);
channel->caller_extension = caller_extension;

View File

@ -83,7 +83,7 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char
*var = *val = NULL;
for(;;) {
for (;;) {
cfg->lineno++;
if (!fgets(cfg->buf, sizeof(cfg->buf), cfg->file)) {
@ -154,6 +154,3 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char
return ret;
}

View File

@ -54,15 +54,10 @@ static int switch_console_process(char *cmd)
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"\n"
"Valid Commands:\n\n"
"version\n"
"help - umm yeah..\n"
"%sshutdown - stop the program\n\n",
perlhelp
);
"version\n" "help - umm yeah..\n" "%sshutdown - stop the program\n\n", perlhelp);
return 1;
}
#ifdef EMBED_PERL
if (!strncmp(cmd, "perl ", 5)) {
cmd += 5;
@ -71,7 +66,7 @@ static int switch_console_process(char *cmd)
return 1;
}
#endif
if ((arg = strchr(cmd, '\r')) || (arg=strchr(cmd, '\n'))) {
if ((arg = strchr(cmd, '\r')) || (arg = strchr(cmd, '\n'))) {
*arg = '\0';
arg = NULL;
}
@ -79,14 +74,16 @@ static int switch_console_process(char *cmd)
*arg++ = '\0';
}
if (switch_api_execute(cmd, arg, retbuf, sizeof(retbuf)) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf);
switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "",
retbuf);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Unknown Command: %s\n", cmd);
}
return 1;
}
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line, char *fmt, ...)
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line,
char *fmt, ...)
{
char *data;
int ret = 0;
@ -120,18 +117,18 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
if (channel == SWITCH_CHANNEL_ID_CONSOLE) {
fprintf(handle, "[%d] %s %s:%d %s() %s", (int)getpid(), date, filep, line, func, data);
fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data);
}
else if (channel == SWITCH_CHANNEL_ID_EVENT &&
switch_event_running() == SWITCH_STATUS_SUCCESS &&
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_running() == SWITCH_STATUS_SUCCESS &&
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_fire(&event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_fire(&event);
}
free(data);
}
@ -161,14 +158,14 @@ SWITCH_DECLARE(void) switch_console_loop(void)
}
memset(&cmd, 0, sizeof(cmd));
for (x=0; sizeof(cmd) ;x++) {
for (x = 0; sizeof(cmd); x++) {
cmd[x] = getchar();
if (cmd[x] == '\n') {
cmd[x] = '\0';
break;
}
}
if(cmd[0]) {
if (cmd[0]) {
running = switch_console_process(cmd);
}
}

View File

@ -35,8 +35,8 @@
#include <EXTERN.h>
#include <perl.h>
static char *embedding[] = { "", "-e", ""};
EXTERN_C void xs_init (pTHX);
static char *embedding[] = { "", "-e", "" };
EXTERN_C void xs_init(pTHX);
#endif
@ -81,7 +81,7 @@ struct switch_core_session {
void *streams[SWITCH_MAX_STREAMS];
int stream_count;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
void *private;
};
@ -100,7 +100,7 @@ struct switch_core_runtime {
/* Prototypes */
static int handle_SIGINT(int sig);
static int handle_SIGPIPE(int sig);
static void * SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj);
static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj);
static void switch_core_standard_on_init(switch_core_session *session);
static void switch_core_standard_on_hangup(switch_core_session *session);
static void switch_core_standard_on_ring(switch_core_session *session);
@ -154,7 +154,7 @@ SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename)
if (switch_core_db_open(path, &db)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
switch_core_db_close(db);
db=NULL;
db = NULL;
}
return db;
}
@ -186,7 +186,7 @@ SWITCH_DECLARE(switch_status) switch_core_do_perl(char *txt)
}
#endif
SWITCH_DECLARE (switch_status) switch_core_session_message_send(char *uuid_str, switch_core_session_message *message)
SWITCH_DECLARE(switch_status) switch_core_session_message_send(char *uuid_str, switch_core_session_message *message)
{
switch_core_session *session = NULL;
@ -221,7 +221,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_write_codec(switch_core_se
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, int channels, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms,
int channels, switch_codec_flag flags,
const switch_codec_settings *codec_settings,
switch_memory_pool *pool)
{
const switch_codec_interface *codec_interface;
const switch_codec_implementation *iptr, *implementation = NULL;
@ -236,7 +239,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *
return SWITCH_STATUS_GENERR;
}
for(iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
if ((!rate || rate == iptr->samples_per_second) &&
(!ms || ms == (iptr->microseconds_per_frame / 1000)) &&
(!channels || channels == iptr->number_of_channels)) {
@ -263,7 +266,8 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *
return SWITCH_STATUS_SUCCESS;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s Exists but not then desired implementation.\n", codec_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s Exists but not then desired implementation.\n",
codec_name);
}
return SWITCH_STATUS_NOTIMPL;
@ -276,9 +280,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
size_t decoded_data_len,
int decoded_rate,
void *encoded_data,
size_t *encoded_data_len,
int *encoded_rate,
unsigned int *flag)
size_t *encoded_data_len, int *encoded_rate, unsigned int *flag)
{
assert(codec != NULL);
assert(encoded_data != NULL);
@ -299,11 +301,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
other_codec,
decoded_data,
decoded_data_len,
decoded_rate,
encoded_data,
encoded_data_len,
encoded_rate,
flag);
decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
}
@ -313,9 +311,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
size_t encoded_data_len,
int encoded_rate,
void *decoded_data,
size_t *decoded_data_len,
int *decoded_rate,
unsigned int *flag)
size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
{
assert(codec != NULL);
@ -337,11 +333,7 @@ SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
other_codec,
encoded_data,
encoded_data_len,
encoded_rate,
decoded_data,
decoded_data_len,
decoded_rate,
flag);
encoded_rate, decoded_data, decoded_data_len, decoded_rate, flag);
}
@ -363,7 +355,8 @@ SWITCH_DECLARE(switch_status) switch_core_codec_destroy(switch_codec *codec)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char *file_path, unsigned int flags, switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char *file_path, unsigned int flags,
switch_memory_pool *pool)
{
char *ext;
switch_status status;
@ -398,17 +391,18 @@ SWITCH_DECLARE(switch_status) switch_core_file_read(switch_file_handle *fh, void
{
assert(fh != NULL);
return fh->file_interface->file_read(fh, data, (unsigned int *)len);
return fh->file_interface->file_read(fh, data, (unsigned int *) len);
}
SWITCH_DECLARE(switch_status) switch_core_file_write(switch_file_handle *fh, void *data, size_t *len)
{
assert(fh != NULL);
return fh->file_interface->file_write(fh, data, (unsigned int *)len);
return fh->file_interface->file_write(fh, data, (unsigned int *) len);
}
SWITCH_DECLARE(switch_status) switch_core_file_seek(switch_file_handle *fh, unsigned int *cur_pos, unsigned int samples, int whence)
SWITCH_DECLARE(switch_status) switch_core_file_seek(switch_file_handle *fh, unsigned int *cur_pos, unsigned int samples,
int whence)
{
return fh->file_interface->file_seek(fh, cur_pos, samples, whence);
}
@ -419,7 +413,8 @@ SWITCH_DECLARE(switch_status) switch_core_file_close(switch_file_handle *fh)
}
SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples, switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples,
switch_memory_pool *pool)
{
switch_timer_interface *timer_interface;
switch_status status;
@ -498,8 +493,8 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj)
return NULL;
#endif
while(data->running > 0) {
switch(switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
while (data->running > 0) {
switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
case SWITCH_STATUS_SUCCESS:
break;
case SWITCH_STATUS_TIMEOUT:
@ -527,13 +522,14 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session *
if (thread_session->running > 0) {
thread_session->running = -1;
while(thread_session->running) {
while (thread_session->running) {
switch_yield(1000);
}
}
}
SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, switch_core_thread_session *thread_session, int stream_id)
SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session,
switch_core_thread_session *thread_session, int stream_id)
{
thread_session->running = 1;
thread_session->objs[0] = session;
@ -548,7 +544,7 @@ SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_se
/* **ONLY** alloc things with this function that **WILL NOT** outlive
the session itself or expect an earth shattering KABOOM!*/
SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory)
SWITCH_DECLARE(void *) switch_core_session_alloc(switch_core_session *session, size_t memory)
{
void *ptr = NULL;
assert(session != NULL);
@ -581,7 +577,8 @@ SWITCH_DECLARE(char *) switch_core_permenant_strdup(char *todup)
assert(runtime.memory_pool != NULL);
if (!todup) return NULL;
if (!todup)
return NULL;
len = strlen(todup) + 1;
if (todup && (duped = apr_palloc(runtime.memory_pool, len))) {
@ -598,7 +595,8 @@ SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session *session,
assert(session != NULL);
assert(session->pool != NULL);
if (!todup) return NULL;
if (!todup)
return NULL;
len = strlen(todup) + 1;
@ -616,7 +614,8 @@ SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup)
assert(pool != NULL);
assert(todup != NULL);
if (!todup) return NULL;
if (!todup)
return NULL;
len = strlen(todup) + 1;
if (todup && (duped = apr_palloc(pool, len))) {
@ -671,8 +670,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s
}
if (endpoint_interface->io_routines->outgoing_channel) {
if ((status = endpoint_interface->io_routines->outgoing_channel(session, caller_profile, new_session)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.outgoing_channel; ptr ; ptr = ptr->next) {
if ((status =
endpoint_interface->io_routines->outgoing_channel(session, caller_profile,
new_session)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) {
if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -716,7 +717,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_answer_channel(switch_core_ses
assert(session != NULL);
if (session->endpoint_interface->io_routines->answer_channel) {
if ((status = session->endpoint_interface->io_routines->answer_channel(session)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.answer_channel; ptr ; ptr = ptr->next) {
for (ptr = session->event_hooks.answer_channel; ptr; ptr = ptr->next) {
if ((status = ptr->answer_channel(session)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -729,15 +730,17 @@ SWITCH_DECLARE(switch_status) switch_core_session_answer_channel(switch_core_ses
return status;
}
SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_session *session, switch_core_session_message *message)
SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_session *session,
switch_core_session_message *message)
{
struct switch_io_event_hook_receive_message *ptr;
switch_status status = SWITCH_STATUS_FALSE;
assert(session != NULL);
if (session->endpoint_interface->io_routines->receive_message) {
if ((status = session->endpoint_interface->io_routines->receive_message(session, message)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.receive_message; ptr ; ptr = ptr->next) {
if ((status =
session->endpoint_interface->io_routines->receive_message(session, message)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.receive_message; ptr; ptr = ptr->next) {
if ((status = ptr->receive_message(session, message)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -750,7 +753,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_receive_message(switch_core_se
return status;
}
SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame, int timeout, int stream_id)
SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session *session, switch_frame **frame,
int timeout, int stream_id)
{
struct switch_io_event_hook_read_frame *ptr;
switch_status status = SWITCH_STATUS_FALSE;
@ -763,8 +767,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
timeout,
SWITCH_IO_FLAG_NOOP,
stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.read_frame; ptr ; ptr = ptr->next) {
if ((status = ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP, stream_id)) != SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) {
if ((status =
ptr->read_frame(session, frame, timeout, SWITCH_IO_FLAG_NOOP,
stream_id)) != SWITCH_STATUS_SUCCESS) {
break;
}
}
@ -776,7 +782,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
}
/* if you think this code is redundant.... too bad! I like to understand what I'm doing */
if ((session->read_codec && (*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
if ((session->read_codec && (*frame)->codec
&& session->read_codec->implementation != (*frame)->codec->implementation)) {
need_codec = TRUE;
}
@ -800,9 +807,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
read_frame->datalen,
session->read_codec->implementation->samples_per_second,
session->raw_read_frame.data,
&session->raw_read_frame.datalen,
&session->raw_read_frame.rate,
&flag);
&session->raw_read_frame.datalen, &session->raw_read_frame.rate, &flag);
switch (status) {
case SWITCH_STATUS_RESAMPLE:
@ -811,8 +816,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
read_frame->codec->implementation->samples_per_second,
read_frame->codec->implementation->bytes_per_frame * 20,
session->read_codec->implementation->samples_per_second,
session->read_codec->implementation->bytes_per_frame * 20,
session->pool);
session->read_codec->implementation->bytes_per_frame * 20, session->pool);
}
case SWITCH_STATUS_SUCCESS:
read_frame = &session->raw_read_frame;
@ -821,7 +825,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
status = SWITCH_STATUS_SUCCESS;
break;
default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n",
session->read_codec->codec_interface->interface_name);
return status;
break;
}
@ -829,13 +834,12 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
if (session->read_resampler) {
short *data = read_frame->data;
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int)read_frame->datalen / 2 );
session->read_resampler->to_len = switch_resample_process(session->read_resampler,
session->read_resampler->from,
session->read_resampler->from_len,
session->read_resampler->to,
(int)session->read_resampler->to_size,
0);
session->read_resampler->from_len =
switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
session->read_resampler->to_len =
switch_resample_process(session->read_resampler, session->read_resampler->from,
session->read_resampler->from_len, session->read_resampler->to,
(int) session->read_resampler->to_size, 0);
switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
read_frame->samples = session->read_resampler->to_len;
read_frame->datalen = session->read_resampler->to_len * 2;
@ -846,7 +850,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) {
perfect = TRUE;
} else {
if (! session->raw_read_buffer) {
if (!session->raw_read_buffer) {
int bytes = session->read_codec->implementation->bytes_per_frame * 10;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Engaging Read Buffer at %d bytes\n", bytes);
switch_buffer_create(session->pool, &session->raw_read_buffer, bytes);
@ -865,7 +869,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
} else {
session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer,
session->raw_read_frame.data,
session->read_codec->implementation->bytes_per_frame);
session->read_codec->implementation->
bytes_per_frame);
session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second;
enc_frame = &session->raw_read_frame;
}
@ -877,8 +882,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
(*frame)->codec->implementation->samples_per_second,
session->enc_read_frame.data,
&session->enc_read_frame.datalen,
&session->enc_read_frame.rate,
&flag);
&session->enc_read_frame.rate, &flag);
switch (status) {
@ -892,7 +896,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
status = SWITCH_STATUS_SUCCESS;
break;
default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n",
session->read_codec->codec_interface->interface_name);
*frame = NULL;
status = SWITCH_STATUS_GENERR;
break;
@ -904,13 +909,17 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
return status;
}
static switch_status perform_write(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id) {
static switch_status perform_write(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags,
int stream_id)
{
struct switch_io_event_hook_write_frame *ptr;
switch_status status = SWITCH_STATUS_FALSE;
if (session->endpoint_interface->io_routines->write_frame) {
if ((status = session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.write_frame; ptr ; ptr = ptr->next) {
if ((status =
session->endpoint_interface->io_routines->write_frame(session, frame, timeout, flags,
stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.write_frame; ptr; ptr = ptr->next) {
if ((status = ptr->write_frame(session, frame, timeout, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -920,7 +929,8 @@ static switch_status perform_write(switch_core_session *session, switch_frame *f
return status;
}
SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame, int timeout, int stream_id)
SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_session *session, switch_frame *frame,
int timeout, int stream_id)
{
switch_status status = SWITCH_STATUS_FALSE;
@ -950,9 +960,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
frame->datalen,
session->write_codec->implementation->samples_per_second,
session->raw_write_frame.data,
&session->raw_write_frame.datalen,
&session->raw_write_frame.rate,
&flag);
&session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag);
switch (status) {
case SWITCH_STATUS_RESAMPLE:
@ -974,7 +982,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
status = SWITCH_STATUS_SUCCESS;
break;
default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n",
frame->codec->codec_interface->interface_name);
return status;
break;
}
@ -982,13 +991,12 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
if (session->write_resampler) {
short *data = write_frame->data;
session->write_resampler->from_len = switch_short_to_float(data, session->write_resampler->from, (int)write_frame->datalen / 2);
session->write_resampler->to_len = switch_resample_process(session->write_resampler,
session->write_resampler->from,
session->write_resampler->from_len,
session->write_resampler->to,
(int)session->write_resampler->to_size,
0);
session->write_resampler->from_len =
switch_short_to_float(data, session->write_resampler->from, (int) write_frame->datalen / 2);
session->write_resampler->to_len =
switch_resample_process(session->write_resampler, session->write_resampler->from,
session->write_resampler->from_len, session->write_resampler->to,
(int) session->write_resampler->to_size, 0);
switch_float_to_short(session->write_resampler->to, data, write_frame->datalen * 2);
write_frame->samples = session->write_resampler->to_len;
write_frame->datalen = session->write_resampler->to_len * 2;
@ -1003,9 +1011,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Engaging Write Buffer at %d bytes to accomidate %d->%d\n",
bytes,
write_frame->datalen,
session->write_codec->implementation->bytes_per_frame);
if ((status = switch_buffer_create(session->pool, &session->raw_write_buffer, bytes)) != SWITCH_STATUS_SUCCESS) {
write_frame->datalen, session->write_codec->implementation->bytes_per_frame);
if ((status =
switch_buffer_create(session->pool, &session->raw_write_buffer,
bytes)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n");
return status;
}
@ -1026,8 +1035,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
session->write_codec->implementation->samples_per_second,
session->enc_write_frame.data,
&session->enc_write_frame.datalen,
&session->enc_write_frame.rate,
&flag);
&session->enc_write_frame.rate, &flag);
switch (status) {
case SWITCH_STATUS_RESAMPLE:
@ -1040,7 +1048,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
status = SWITCH_STATUS_SUCCESS;
break;
default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n",
session->read_codec->codec_interface->interface_name);
write_frame = NULL;
return status;
break;
@ -1058,9 +1067,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
int x;
for (x = 0; x < frames; x++) {
if ((session->raw_write_frame.datalen =
switch_buffer_read(session->raw_write_buffer,
session->raw_write_frame.data,
bytes))) {
switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, bytes))) {
enc_frame = &session->raw_write_frame;
session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
@ -1072,8 +1079,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
frame->codec->implementation->samples_per_second,
session->enc_write_frame.data,
&session->enc_write_frame.datalen,
&session->enc_write_frame.rate,
&flag);
&session->enc_write_frame.rate, &flag);
@ -1084,9 +1090,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
status = switch_resample_create(&session->read_resampler,
frame->codec->implementation->samples_per_second,
frame->codec->implementation->bytes_per_frame * 20,
session->write_codec->implementation->samples_per_second,
session->write_codec->implementation->bytes_per_frame * 20,
session->pool);
session->write_codec->implementation->
samples_per_second,
session->write_codec->implementation->
bytes_per_frame * 20, session->pool);
}
break;
case SWITCH_STATUS_SUCCESS:
@ -1097,7 +1104,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
status = SWITCH_STATUS_SUCCESS;
break;
default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n",
session->read_codec->codec_interface->interface_name);
write_frame = NULL;
return status;
break;
@ -1108,13 +1116,13 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
session->read_resampler->from_len = switch_short_to_float(data,
session->read_resampler->from,
(int)write_frame->datalen / 2);
session->read_resampler->to_len = switch_resample_process(session->read_resampler,
session->read_resampler->from,
session->read_resampler->from_len,
session->read_resampler->to,
(int)session->read_resampler->to_size,
0);
(int) write_frame->datalen /
2);
session->read_resampler->to_len =
switch_resample_process(session->read_resampler, session->read_resampler->from,
session->read_resampler->from_len,
session->read_resampler->to,
(int) session->read_resampler->to_size, 0);
switch_float_to_short(session->read_resampler->to, data, write_frame->datalen * 2);
write_frame->samples = session->read_resampler->to_len;
write_frame->datalen = session->read_resampler->to_len * 2;
@ -1140,7 +1148,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_kill_channel(switch_core_sessi
if (session->endpoint_interface->io_routines->kill_channel) {
if ((status = session->endpoint_interface->io_routines->kill_channel(session, sig)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.kill_channel; ptr ; ptr = ptr->next) {
for (ptr = session->event_hooks.kill_channel; ptr; ptr = ptr->next) {
if ((status = ptr->kill_channel(session, sig)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -1158,8 +1166,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_sessi
switch_status status = SWITCH_STATUS_FALSE;
if (session->endpoint_interface->io_routines->waitfor_read) {
if ((status = session->endpoint_interface->io_routines->waitfor_read(session, timeout, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.waitfor_read; ptr ; ptr = ptr->next) {
if ((status =
session->endpoint_interface->io_routines->waitfor_read(session, timeout,
stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.waitfor_read; ptr; ptr = ptr->next) {
if ((status = ptr->waitfor_read(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -1171,14 +1181,17 @@ SWITCH_DECLARE(switch_status) switch_core_session_waitfor_read(switch_core_sessi
}
SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout, int stream_id)
SWITCH_DECLARE(switch_status) switch_core_session_waitfor_write(switch_core_session *session, int timeout,
int stream_id)
{
struct switch_io_event_hook_waitfor_write *ptr;
switch_status status = SWITCH_STATUS_FALSE;
if (session->endpoint_interface->io_routines->waitfor_write) {
if ((status = session->endpoint_interface->io_routines->waitfor_write(session, timeout, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.waitfor_write; ptr ; ptr = ptr->next) {
if ((status =
session->endpoint_interface->io_routines->waitfor_write(session, timeout,
stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.waitfor_write; ptr; ptr = ptr->next) {
if ((status = ptr->waitfor_write(session, timeout, stream_id)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -1197,7 +1210,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_send_dtmf(switch_core_session
if (session->endpoint_interface->io_routines->send_dtmf) {
if ((status = session->endpoint_interface->io_routines->send_dtmf(session, dtmf)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.send_dtmf; ptr ; ptr = ptr->next) {
for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) {
if ((status = ptr->send_dtmf(session, dtmf)) != SWITCH_STATUS_SUCCESS) {
break;
}
@ -1208,7 +1221,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_send_dtmf(switch_core_session
return status;
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch_core_session *session, switch_outgoing_channel_hook outgoing_channel)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch_core_session *session,
switch_outgoing_channel_hook outgoing_channel)
{
switch_io_event_hook_outgoing_channel *hook, *ptr;
@ -1218,7 +1232,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch
if (!session->event_hooks.outgoing_channel) {
session->event_hooks.outgoing_channel = hook;
} else {
for(ptr = session->event_hooks.outgoing_channel ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.outgoing_channel; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1229,7 +1243,9 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_outgoing(switch
return SWITCH_STATUS_MEMERR;
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel(switch_core_session *session, switch_answer_channel_hook answer_channel)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel(switch_core_session *session,
switch_answer_channel_hook
answer_channel)
{
switch_io_event_hook_answer_channel *hook, *ptr;
@ -1239,7 +1255,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel(
if (!session->event_hooks.answer_channel) {
session->event_hooks.answer_channel = hook;
} else {
for(ptr = session->event_hooks.answer_channel ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.answer_channel; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1251,7 +1267,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_answer_channel(
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(switch_core_session *session, switch_read_frame_hook read_frame)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(switch_core_session *session,
switch_read_frame_hook read_frame)
{
switch_io_event_hook_read_frame *hook, *ptr;
@ -1261,7 +1278,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(swit
if (!session->event_hooks.read_frame) {
session->event_hooks.read_frame = hook;
} else {
for(ptr = session->event_hooks.read_frame ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.read_frame; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1273,7 +1290,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_read_frame(swit
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(switch_core_session *session, switch_write_frame_hook write_frame)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(switch_core_session *session,
switch_write_frame_hook write_frame)
{
switch_io_event_hook_write_frame *hook, *ptr;
@ -1283,7 +1301,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(swi
if (!session->event_hooks.write_frame) {
session->event_hooks.write_frame = hook;
} else {
for(ptr = session->event_hooks.write_frame ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.write_frame; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1295,7 +1313,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_write_frame(swi
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(switch_core_session *session, switch_kill_channel_hook kill_channel)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(switch_core_session *session,
switch_kill_channel_hook kill_channel)
{
switch_io_event_hook_kill_channel *hook, *ptr;
@ -1305,7 +1324,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(sw
if (!session->event_hooks.kill_channel) {
session->event_hooks.kill_channel = hook;
} else {
for(ptr = session->event_hooks.kill_channel ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.kill_channel; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1317,7 +1336,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_kill_channel(sw
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(switch_core_session *session, switch_waitfor_read_hook waitfor_read)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(switch_core_session *session,
switch_waitfor_read_hook waitfor_read)
{
switch_io_event_hook_waitfor_read *hook, *ptr;
@ -1327,7 +1347,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(sw
if (!session->event_hooks.waitfor_read) {
session->event_hooks.waitfor_read = hook;
} else {
for(ptr = session->event_hooks.waitfor_read ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.waitfor_read; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1339,7 +1359,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(sw
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(switch_core_session *session, switch_waitfor_write_hook waitfor_write)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(switch_core_session *session,
switch_waitfor_write_hook waitfor_write)
{
switch_io_event_hook_waitfor_write *hook, *ptr;
@ -1349,7 +1370,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(s
if (!session->event_hooks.waitfor_write) {
session->event_hooks.waitfor_write = hook;
} else {
for(ptr = session->event_hooks.waitfor_write ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.waitfor_write; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1362,7 +1383,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(s
}
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switch_core_session *session, switch_send_dtmf_hook send_dtmf)
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switch_core_session *session,
switch_send_dtmf_hook send_dtmf)
{
switch_io_event_hook_send_dtmf *hook, *ptr;
@ -1372,7 +1394,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switc
if (!session->event_hooks.send_dtmf) {
session->event_hooks.send_dtmf = hook;
} else {
for(ptr = session->event_hooks.send_dtmf ; ptr && ptr->next; ptr = ptr->next);
for (ptr = session->event_hooks.send_dtmf; ptr && ptr->next; ptr = ptr->next);
ptr->next = hook;
}
@ -1459,16 +1481,21 @@ static void switch_core_standard_on_execute(switch_core_session *session)
}
while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", extension->current_application->application_name,
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n",
extension->current_application->application_name,
extension->current_application->application_data);
if (!(application_interface = switch_loadable_module_get_application_interface(extension->current_application->application_name))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name);
if (!
(application_interface =
switch_loadable_module_get_application_interface(extension->current_application->application_name))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n",
extension->current_application->application_name);
switch_channel_set_state(session->channel, CS_HANGUP);
return;
}
if (!application_interface->application_function) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Function for %s\n", extension->current_application->application_name);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Function for %s\n",
extension->current_application->application_name);
switch_channel_set_state(session->channel, CS_HANGUP);
return;
}
@ -1489,7 +1516,7 @@ static void switch_core_standard_on_loopback(switch_core_session *session)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard LOOPBACK\n");
while ((state = switch_channel_get_state(session->channel)) == CS_LOOPBACK) {
for(stream_id = 0; stream_id < session->stream_count; stream_id++) {
for (stream_id = 0; stream_id < session->stream_count; stream_id++) {
if (switch_core_session_read_frame(session, &frame, -1, stream_id) == SWITCH_STATUS_SUCCESS) {
switch_core_session_write_frame(session, frame, -1, stream_id);
}
@ -1516,20 +1543,20 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
const switch_event_handler_table *application_event_handlers = NULL;
/*
Life of the channel. you have channel and pool in your session
everywhere you go you use the session to malloc with
switch_core_session_alloc(session, <size>)
Life of the channel. you have channel and pool in your session
everywhere you go you use the session to malloc with
switch_core_session_alloc(session, <size>)
The enpoint module gets the first crack at implementing the state
if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE
The enpoint module gets the first crack at implementing the state
if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE
Next comes the channel's event handler table that can be set by an application
which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE
Next comes the channel's event handler table that can be set by an application
which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE
Finally the default state behaviour is called.
Finally the default state behaviour is called.
*/
*/
assert(session != NULL);
application_event_handlers = switch_channel_get_event_handlers(session->channel);
@ -1552,14 +1579,14 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
switch_event_fire(&event);
}
switch ( state ) {
case CS_NEW: /* Just created, Waiting for first instructions */
switch (state) {
case CS_NEW: /* Just created, Waiting for first instructions */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n");
break;
case CS_DONE:
continue;
break;
case CS_HANGUP: /* Deactivate and end the thread */
case CS_HANGUP: /* Deactivate and end the thread */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n");
if (!driver_event_handlers->on_hangup ||
(driver_event_handlers->on_hangup &&
@ -1574,7 +1601,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
switch_channel_set_state(session->channel, CS_DONE);
break;
case CS_INIT: /* Basic setup tasks */
case CS_INIT: /* Basic setup tasks */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n");
if (!driver_event_handlers->on_init ||
(driver_event_handlers->on_init &&
@ -1588,7 +1615,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
}
break;
case CS_RING: /* Look for a dialplan and find something to do */
case CS_RING: /* Look for a dialplan and find something to do */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n");
if (!driver_event_handlers->on_ring ||
(driver_event_handlers->on_ring &&
@ -1602,7 +1629,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
}
break;
case CS_EXECUTE: /* Execute an Operation*/
case CS_EXECUTE: /* Execute an Operation */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n");
if (!driver_event_handlers->on_execute ||
(driver_event_handlers->on_execute &&
@ -1616,7 +1643,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
}
break;
case CS_LOOPBACK: /* loop all data back to source */
case CS_LOOPBACK: /* loop all data back to source */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n");
if (!driver_event_handlers->on_loopback ||
(driver_event_handlers->on_loopback &&
@ -1630,7 +1657,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
}
}
break;
case CS_TRANSMIT: /* send/recieve data to/from another channel */
case CS_TRANSMIT: /* send/recieve data to/from another channel */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n");
if (!driver_event_handlers->on_transmit ||
(driver_event_handlers->on_transmit &&
@ -1741,17 +1768,12 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void
}
ts->objs[0] = obj;
switch_thread_create(&thread,
thd_attr,
func,
ts,
pool
);
switch_thread_create(&thread, thd_attr, func, ts, pool);
}
}
static void * SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj)
static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *thread, void *obj)
{
switch_core_session *session = obj;
@ -1759,7 +1781,7 @@ static void * SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread *threa
session->thread = thread;
session->id = runtime.session_id++;
if(runtime.session_id >= sizeof(unsigned long))
if (runtime.session_id >= sizeof(unsigned long))
runtime.session_id = 1;
snprintf(session->name, sizeof(session->name), "%ld", session->id);
@ -1781,30 +1803,21 @@ SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session *sess
switch_threadattr_create(&thd_attr, session->pool);
switch_threadattr_detach_set(thd_attr, 1);
if (switch_thread_create(&thread,
thd_attr,
switch_core_session_thread,
session,
session->pool
) != APR_SUCCESS) {
if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) != APR_SUCCESS) {
switch_core_session_destroy(&session);
}
}
SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, switch_thread_start_t func, void *obj)
SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, switch_thread_start_t func,
void *obj)
{
switch_thread *thread;
switch_threadattr_t *thd_attr = NULL;
switch_threadattr_create(&thd_attr, session->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_thread_create(&thread,
thd_attr,
func,
obj,
session->pool
);
switch_thread_create(&thread, thd_attr, func, obj, session->pool);
}
@ -1820,7 +1833,8 @@ SWITCH_DECLARE(void *) switch_core_alloc(switch_memory_pool *pool, size_t memory
return ptr;
}
SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_endpoint_interface *endpoint_interface, switch_memory_pool *pool)
SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_endpoint_interface *endpoint_interface,
switch_memory_pool *pool)
{
switch_memory_pool *usepool;
switch_core_session *session;
@ -1869,7 +1883,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e
session->enc_read_frame.data = session->enc_read_buf;
session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED ,session->pool);
switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_thread_cond_create(&session->cond, session->pool);
return session;
@ -1888,11 +1902,11 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request_by_name(char *
}
static void core_event_handler (switch_event *event)
static void core_event_handler(switch_event *event)
{
char buf[1024];
switch(event->event_id) {
switch (event->event_id) {
case SWITCH_EVENT_LOG:
return;
break;
@ -1936,13 +1950,14 @@ SWITCH_DECLARE(switch_status) switch_core_init(void)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening DB!\n");
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening DB\n");
if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL) !=
SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind event handler!\n");
}
}
#ifdef EMBED_PERL
if (! (my_perl = perl_alloc())) {
if (!(my_perl = perl_alloc())) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate perl intrepreter\n");
switch_core_destroy();
return SWITCH_STATUS_MEMERR;
@ -1961,12 +1976,12 @@ SWITCH_DECLARE(switch_status) switch_core_init(void)
switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
/* set signal handlers and startup time */
(void) signal(SIGINT,(void *) handle_SIGINT);
(void) signal(SIGINT, (void *) handle_SIGINT);
#ifdef SIGPIPE
(void) signal(SIGPIPE,(void *) handle_SIGPIPE);
(void) signal(SIGPIPE, (void *) handle_SIGPIPE);
#endif
#ifdef TRAP_BUS
(void) signal(SIGBUS,(void *) handle_SIGBUS);
(void) signal(SIGBUS, (void *) handle_SIGBUS);
#endif
time(&runtime.initiated);
@ -2000,4 +2015,3 @@ SWITCH_DECLARE(switch_status) switch_core_destroy(void)
return SWITCH_STATUS_SUCCESS;
}

View File

@ -31,7 +31,7 @@
*/
#include <switch_event.h>
static switch_event_node *EVENT_NODES[SWITCH_EVENT_ALL+1] = {NULL};
static switch_event_node *EVENT_NODES[SWITCH_EVENT_ALL + 1] = { NULL };
static switch_mutex_t *BLOCK = NULL;
static switch_mutex_t *POOL_LOCK = NULL;
static switch_memory_pool *RUNTIME_POOL = NULL;
@ -59,10 +59,10 @@ static void *locked_alloc(size_t len)
void *mem;
switch_mutex_lock(POOL_LOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
mem = switch_core_alloc(THRUNTIME_POOL, len);
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> ----------------------------------------------*/
/* </LOCKED> ---------------------------------------------- */
return mem;
}
@ -72,13 +72,14 @@ static void *locked_dup(char *str)
char *dup;
switch_mutex_lock(POOL_LOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
dup = switch_core_strdup(THRUNTIME_POOL, str);
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> ----------------------------------------------*/
/* </LOCKED> ---------------------------------------------- */
return dup;
}
#define ALLOC(size) locked_alloc(size)
#define DUP(str) locked_dup(str)
#endif
@ -139,7 +140,7 @@ static int switch_events_match(switch_event *event, switch_event_node *node)
return match;
}
static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void *obj)
static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void *obj)
{
switch_event_node *node;
switch_event *out_event = NULL;
@ -149,11 +150,11 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void
assert(POOL_LOCK != NULL);
assert(RUNTIME_POOL != NULL);
THREAD_RUNNING = 1;
while(THREAD_RUNNING == 1 || switch_queue_size(EVENT_QUEUE)) {
while (THREAD_RUNNING == 1 || switch_queue_size(EVENT_QUEUE)) {
#ifdef MALLOC_EVENTS
switch_mutex_lock(POOL_LOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
if (POOL_COUNT >= POOL_COUNT_MAX) {
if (THRUNTIME_POOL == APOOL) {
THRUNTIME_POOL = BPOOL;
@ -164,14 +165,14 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void
POOL_COUNT = 0;
}
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> -----------------------------------------------*/
/* </LOCKED> ----------------------------------------------- */
#endif
while (switch_queue_trypop(EVENT_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
out_event = pop;
for(e = out_event->event_id;; e = SWITCH_EVENT_ALL) {
for(node = EVENT_NODES[e]; node; node = node->next) {
for (e = out_event->event_id;; e = SWITCH_EVENT_ALL) {
for (node = EVENT_NODES[e]; node; node = node->next) {
if (switch_events_match(out_event, node)) {
out_event->bind_user_data = node->user_data;
node->callback(out_event);
@ -234,7 +235,7 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void)
{
THREAD_RUNNING = -1;
while(THREAD_RUNNING) {
while (THREAD_RUNNING) {
switch_yield(1000);
}
return SWITCH_STATUS_SUCCESS;
@ -267,31 +268,26 @@ SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool)
switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
switch_mutex_init(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL);
switch_thread_create(&thread,
thd_attr,
switch_event_thread,
NULL,
RUNTIME_POOL
);
switch_thread_create(&thread, thd_attr, switch_event_thread, NULL, RUNTIME_POOL);
while(!THREAD_RUNNING) {
while (!THREAD_RUNNING) {
switch_yield(1000);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, char *subclass_name)
SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id,
char *subclass_name)
{
if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) {
return SWITCH_STATUS_GENERR;
}
if(!(*event = ALLOC(sizeof(switch_event)))) {
if (!(*event = ALLOC(sizeof(switch_event)))) {
return SWITCH_STATUS_MEMERR;
}
#ifdef MALLOC_EVENTS
memset(*event, 0, sizeof(switch_event));
#endif
@ -309,7 +305,7 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
{
switch_event_header *hp;
if (header_name) {
for(hp = event->headers; hp; hp = hp->next) {
for (hp = event->headers; hp; hp = hp->next) {
if (!strcasecmp(hp->name, header_name)) {
return hp->value;
}
@ -318,7 +314,8 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
return NULL;
}
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...)
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name,
char *fmt, ...)
{
int ret = 0;
char data[2048];
@ -459,7 +456,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
for (hp = event->headers; hp; hp = hp->next) {
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
snprintf(buf + len, buflen - len, "%s: %s\n", hp->name, hp->value);
len = strlen(buf);
}
@ -471,14 +468,14 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
if (body) {
int blen = (int)strlen(body);
int blen = (int) strlen(body);
if (blen) {
snprintf(buf+len, buflen-len, "Content-Length: %d\n\n%s", blen, body);
snprintf(buf + len, buflen - len, "Content-Length: %d\n\n%s", blen, body);
} else {
snprintf(buf+len, buflen-len, "\n");
snprintf(buf + len, buflen - len, "\n");
}
} else {
snprintf(buf+len, buflen-len, "\n");
snprintf(buf + len, buflen - len, "\n");
}
if (data) {
@ -489,7 +486,8 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
}
SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event, void *user_data)
SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, int line, switch_event **event,
void *user_data)
{
switch_time_exp_t tm;
@ -535,7 +533,8 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func,
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, char *subclass_name, switch_event_callback_t callback, void *user_data)
SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event, char *subclass_name,
switch_event_callback_t callback, void *user_data)
{
switch_event_node *event_node;
switch_event_subclass *subclass = NULL;
@ -556,7 +555,7 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event,
if (event <= SWITCH_EVENT_ALL && (event_node = switch_core_alloc(RUNTIME_POOL, sizeof(switch_event_node)))) {
switch_mutex_lock(BLOCK);
/* <LOCKED> -----------------------------------------------*/
/* <LOCKED> ----------------------------------------------- */
event_node->id = switch_core_strdup(RUNTIME_POOL, id);
event_node->event_id = event;
event_node->subclass = subclass;
@ -569,10 +568,9 @@ SWITCH_DECLARE(switch_status) switch_event_bind(char *id, switch_event_t event,
EVENT_NODES[event] = event_node;
switch_mutex_unlock(BLOCK);
/* </LOCKED> -----------------------------------------------*/
/* </LOCKED> ----------------------------------------------- */
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_MEMERR;
}

View File

@ -91,7 +91,8 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj)
return NULL;
}
static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool, switch_loadable_module **new_module)
static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool,
switch_loadable_module **new_module)
{
switch_loadable_module *module = NULL;
apr_dso_handle_t *dso = NULL;
@ -129,7 +130,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem
break;
}
if (! (module = switch_core_permenant_alloc( sizeof(switch_loadable_module) ))) {
if (!(module = switch_core_permenant_alloc(sizeof(switch_loadable_module)))) {
err = "Could not allocate memory\n";
break;
}
@ -192,7 +193,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
char *ptr;
apr_finfo_t finfo;
apr_dir_t *module_dir_handle;
apr_int32_t finfo_flags = APR_FINFO_DIRENT|APR_FINFO_TYPE|APR_FINFO_NAME;
apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
switch_loadable_module *new_module;
#ifdef WIN32
const char *ext = ".dll";
@ -250,9 +251,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
const switch_endpoint_interface *ptr;
for (ptr = new_module->interface->endpoint_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Endpoint '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.endpoint_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.endpoint_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
@ -260,76 +259,64 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
const switch_codec_implementation *impl;
const switch_codec_interface *ptr;
for(ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) {
for(impl = ptr->implementations; impl ; impl = impl->next) {
for (ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) {
for (impl = ptr->implementations; impl; impl = impl->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Adding Codec '%s' (%s) %dkhz %dms\n",
ptr->iananame,
ptr->interface_name,
impl->samples_per_second,
impl->microseconds_per_frame / 1000);
"Adding Codec '%s' (%s) %dkhz %dms\n",
ptr->iananame,
ptr->interface_name,
impl->samples_per_second, impl->microseconds_per_frame / 1000);
}
switch_core_hash_insert(loadable_modules.codec_hash,
(char *) ptr->iananame,
(void *) ptr);
switch_core_hash_insert(loadable_modules.codec_hash, (char *) ptr->iananame, (void *) ptr);
}
}
if (new_module->interface->dialplan_interface) {
const switch_dialplan_interface *ptr;
for(ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Dialplan '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.dialplan_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.dialplan_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->timer_interface) {
const switch_timer_interface *ptr;
for(ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Timer '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.timer_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.timer_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->application_interface) {
const switch_application_interface *ptr;
for(ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Application '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.application_hash,
(char *) ptr->interface_name,
(void *) ptr);
(char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->api_interface) {
const switch_api_interface *ptr;
for(ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding API Function '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.api_hash,
(char *) ptr->interface_name,
(void *) ptr);
switch_core_hash_insert(loadable_modules.api_hash, (char *) ptr->interface_name, (void *) ptr);
}
}
if (new_module->interface->file_interface) {
const switch_file_interface *ptr;
for(ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) {
for (ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) {
int i;
for (i = 0 ; ptr->extens[i]; i++) {
for (i = 0; ptr->extens[i]; i++) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]);
switch_core_hash_insert(loadable_modules.file_hash,
(char *) ptr->extens[i],
(void *) ptr);
switch_core_hash_insert(loadable_modules.file_hash, (char *) ptr->extens[i], (void *) ptr);
}
}
}
@ -344,7 +331,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
{
switch_hash_index_t* hi;
switch_hash_index_t *hi;
void *val;
switch_loadable_module *module;
@ -397,9 +384,10 @@ SWITCH_DECLARE(switch_file_interface *) switch_loadable_module_get_file_interfac
return switch_core_hash_find(loadable_modules.file_hash, name);
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, int arraylen)
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array,
int arraylen)
{
switch_hash_index_t* hi;
switch_hash_index_t *hi;
void *val;
int i = 0;
@ -415,12 +403,13 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool,
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array, int arraylen, char **prefs, int preflen)
SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array,
int arraylen, char **prefs, int preflen)
{
int x, i = 0;
switch_codec_interface *codec_interface;
for(x = 0; x < preflen; x++) {
for (x = 0; x < preflen; x++) {
if ((codec_interface = switch_loadable_module_get_codec_interface(prefs[x]))) {
array[i++] = codec_interface;
}

View File

@ -31,9 +31,7 @@
*/
#include <switch_mutex.h>
SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock,
switch_lock_flag flags,
switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, switch_lock_flag flags, switch_memory_pool *pool)
{
return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;
@ -58,5 +56,3 @@ SWITCH_DECLARE(switch_status) switch_mutex_trylock(switch_mutex_t *lock)
{
return apr_thread_mutex_trylock(lock);
}

View File

@ -49,9 +49,7 @@
SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **new_resampler,
int from_rate,
size_t from_size,
int to_rate,
size_t to_size,
switch_memory_pool *pool)
int to_rate, size_t to_size, switch_memory_pool *pool)
{
switch_audio_resampler *resampler;
@ -61,10 +59,11 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne
resampler->from_rate = from_rate;
resampler->to_rate = to_rate;
resampler->factor = ((double)resampler->to_rate / (double)resampler->from_rate);
resampler->factor = ((double) resampler->to_rate / (double) resampler->from_rate);
resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate, resampler->factor);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Resampler %d->%d %f\n", resampler->from_rate,
resampler->to_rate, resampler->factor);
resampler->from_size = from_size;
resampler->from = (float *) switch_core_alloc(pool, resampler->from_size);
resampler->to_size = to_size;
@ -75,14 +74,16 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne
}
SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst, int dstlen, int last)
SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst,
int dstlen, int last)
{
int o=0, srcused=0, srcpos=0, out=0;
int o = 0, srcused = 0, srcpos = 0, out = 0;
for(;;) {
int srcBlock = MIN(srclen-srcpos, srclen);
int lastFlag = (last && (srcBlock == srclen-srcpos));
o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, &dst[out], dstlen-out);
for (;;) {
int srcBlock = MIN(srclen - srcpos, srclen);
int lastFlag = (last && (srcBlock == srclen - srcpos));
o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused,
&dst[out], dstlen - out);
//printf("resampling %d/%d (%d) %d %f\n", srcpos, srclen, MIN(dstlen-out, dstlen), srcused, factor);
srcpos += srcused;
@ -106,15 +107,17 @@ SWITCH_DECLARE(size_t) switch_float_to_short(float *f, short *s, size_t len)
{
size_t i;
float ft;
for(i=0;i<len;i++) {
for (i = 0; i < len; i++) {
ft = f[i] * NORMFACT;
if(ft >= 0) {
s[i] = (short)(ft+0.5);
if (ft >= 0) {
s[i] = (short) (ft + 0.5);
} else {
s[i] = (short)(ft-0.5);
s[i] = (short) (ft - 0.5);
}
if ((float)s[i] > MAXSAMPLE) s[i] = (short)MAXSAMPLE;
if (s[i] < (short)-MAXSAMPLE) s[i] = (short)-MAXSAMPLE;
if ((float) s[i] > MAXSAMPLE)
s[i] = (short) MAXSAMPLE;
if (s[i] < (short) -MAXSAMPLE)
s[i] = (short) -MAXSAMPLE;
}
return len;
}
@ -124,16 +127,18 @@ SWITCH_DECLARE(int) switch_char_to_float(char *c, float *f, int len)
int i;
if (len % 2) {
return(-1);
return (-1);
}
for(i=1;i<len;i+=2) {
f[(int)(i/2)] = (float)(((c[i])*0x100) + c[i-1]);
f[(int)(i/2)] /= NORMFACT;
if (f[(int)(i/2)] > MAXSAMPLE) f[(int)(i/2)] = MAXSAMPLE;
if (f[(int)(i/2)] < -MAXSAMPLE) f[(int)(i/2)] = -MAXSAMPLE;
for (i = 1; i < len; i += 2) {
f[(int) (i / 2)] = (float) (((c[i]) * 0x100) + c[i - 1]);
f[(int) (i / 2)] /= NORMFACT;
if (f[(int) (i / 2)] > MAXSAMPLE)
f[(int) (i / 2)] = MAXSAMPLE;
if (f[(int) (i / 2)] < -MAXSAMPLE)
f[(int) (i / 2)] = -MAXSAMPLE;
}
return len/2;
return len / 2;
}
SWITCH_DECLARE(int) switch_float_to_char(float *f, char *c, int len)
@ -141,25 +146,25 @@ SWITCH_DECLARE(int) switch_float_to_char(float *f, char *c, int len)
int i;
float ft;
long l;
for(i=0;i<len;i++) {
for (i = 0; i < len; i++) {
ft = f[i] * NORMFACT;
if (ft >= 0) {
l = (long)(ft+0.5);
l = (long) (ft + 0.5);
} else {
l = (long)(ft-0.5);
l = (long) (ft - 0.5);
}
c[i*2] = (unsigned char)((l)&0xff);
c[i*2+1] = (unsigned char)(((l)>>8)&0xff);
c[i * 2] = (unsigned char) ((l) & 0xff);
c[i * 2 + 1] = (unsigned char) (((l) >> 8) & 0xff);
}
return len*2;
return len * 2;
}
SWITCH_DECLARE(int) switch_short_to_float(short *s, float *f, int len)
{
int i;
for(i=0;i<len;i++) {
f[i] = (float)(s[i]) / NORMFACT;
for (i = 0; i < len; i++) {
f[i] = (float) (s[i]) / NORMFACT;
//f[i] = (float) s[i];
}
return len;

View File

@ -73,16 +73,17 @@ SWITCH_DECLARE(char *) switch_cut_path(char *in)
char delims[] = "/\\";
char *i;
for(i = delims; *i; i++) {
for (i = delims; *i; i++) {
p = in;
while((p = strchr(p, *i))) {
while ((p = strchr(p, *i))) {
ret = ++p;
}
}
return ret;
}
SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, unsigned int flags, switch_memory_pool *pool)
SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock,
unsigned int flags, switch_memory_pool *pool)
{
switch_pollset_t *pollset;
switch_status status;
@ -117,6 +118,6 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
void include_me(void)
{
apr_socket_shutdown(NULL, 0);
apr_socket_recvfrom(NULL , NULL, 0, NULL, NULL);
apr_socket_recvfrom(NULL, NULL, 0, NULL, NULL);
}
#endif