RTPIPv4Address addr(destip, tx_port);
RTPSessionParams sessparams;
int status;
-
+
#ifdef WIN32
if (!WSOCKON) {
WSADATA dat;
jrtp4c->transparams->SetPortbase(rx_port);
-
+
if (!(jrtp4c->session = new JRTP4C)) {
*err = "Memory Error!\n";
delete jrtp4c->transparams;
- delete jrtp4c;
- return NULL;
+ delete jrtp4c;
+ return NULL;
}
if ((status = jrtp4c->session->Create(sessparams, jrtp4c->transparams)) < 0) {
return 0;
}
-
+
if ((pack = jrtp4c->session->GetNextPacket())) {
slen = (int)pack->GetPayloadLength();
{\r
struct gsm_context *context;\r
int encoding, decoding;\r
- \r
+\r
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);\r
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);\r
- \r
+\r
if (!(encoding || decoding)) {\r
return SWITCH_STATUS_FALSE;\r
} else {\r
}\r
\r
codec->private = context;\r
- \r
+\r
return SWITCH_STATUS_SUCCESS;\r
- \r
+\r
}\r
\r
static switch_status switch_gsm_destroy(switch_codec *codec)\r
\r
\r
static switch_status switch_gsm_encode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *decoded_data,\r
- size_t decoded_data_len,\r
- int decoded_rate,\r
- void *encoded_data,\r
- size_t *encoded_data_len,\r
- int *encoded_rate,\r
- unsigned int *flag)\r
+ switch_codec *other_codec,\r
+ void *decoded_data,\r
+ size_t decoded_data_len,\r
+ int decoded_rate,\r
+ void *encoded_data,\r
+ size_t *encoded_data_len,\r
+ int *encoded_rate,\r
+ unsigned int *flag)\r
{\r
struct gsm_context *context = codec->private;\r
int cbret = 0;\r
\r
\r
static switch_status switch_gsm_decode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *encoded_data,\r
- size_t encoded_data_len,\r
- int encoded_rate,\r
- void *decoded_data,\r
- size_t *decoded_data_len,\r
- int *decoded_rate,\r
- unsigned int *flag) \r
+ switch_codec *other_codec,\r
+ void *encoded_data,\r
+ size_t encoded_data_len,\r
+ int encoded_rate,\r
+ void *decoded_data,\r
+ size_t *decoded_data_len,\r
+ int *decoded_rate,\r
+ unsigned int *flag) \r
{\r
struct gsm_context *context = codec->private;\r
- \r
+\r
if (!context) {\r
return SWITCH_STATUS_FALSE;\r
}\r
unsigned int new_len = 0;\r
for(x = 0; x < loops && new_len < *decoded_data_len; x++) {\r
gsm_decode(context->decoder, edp, ddp);\r
- ddp += 160;\r
+ ddp += 160;\r
edp += 33;\r
new_len += 320;\r
}\r
} else {\r
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);\r
}\r
- \r
+\r
return SWITCH_STATUS_SUCCESS;\r
}\r
\r
switch_channel *chan_a, *chan_b;
switch_frame *read_frame;
switch_core_session *session_a, *session_b;
-
+
session_a = data->objs[0];
session_b = data->objs[1];
switch_channel_state b_state = switch_channel_get_state(chan_b);
switch (b_state) {
- case CS_HANGUP:
- data->running = -1;
- continue;
- break;
- default:
- break;
+case CS_HANGUP:
+ data->running = -1;
+ continue;
+ break;
+default:
+ break;
}
if (switch_channel_has_dtmf(chan_a)) {
switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL);
switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
-
+
return SWITCH_STATUS_SUCCESS;
}
/*.on_init*/ NULL,
/*.on_ring*/ audio_bridge_on_ring,
/*.on_execute*/ NULL,
- /*.on_hangup*/ audio_bridge_on_hangup,
+ /*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL,
/*.on_transmit*/ NULL
};
/*.on_init*/ NULL,
/*.on_ring*/ NULL,
/*.on_execute*/ NULL,
- /*.on_hangup*/ audio_bridge_on_hangup,
+ /*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL,
/*.on_transmit*/ NULL
};
caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(session,
- caller_caller_profile->dialplan,
- caller_caller_profile->caller_id_name,
- caller_caller_profile->caller_id_number,
- caller_caller_profile->network_addr,
- NULL,
- NULL,
- chan_data);
-
-
-
+ caller_caller_profile->dialplan,
+ caller_caller_profile->caller_id_name,
+ caller_caller_profile->caller_id_number,
+ caller_caller_profile->network_addr,
+ NULL,
+ NULL,
+ chan_data);
+
+
+
if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DOH!\n");
switch_channel_hangup(caller_channel);
} else {
struct switch_core_thread_session this_audio_thread, other_audio_thread;
time_t start;
-
+
peer_channel = switch_core_session_get_channel(peer_session);
memset(&other_audio_thread, 0, sizeof(other_audio_thread));
memset(&this_audio_thread, 0, sizeof(this_audio_thread));
other_audio_thread.objs[0] = session;
other_audio_thread.objs[1] = peer_session;
other_audio_thread.running = 5;
-
+
this_audio_thread.objs[0] = peer_session;
this_audio_thread.objs[1] = session;
this_audio_thread.running = 2;
-
+
switch_channel_set_private(caller_channel, peer_session);
switch_channel_set_private(peer_channel, session);
time(&start);
while(switch_channel_get_state(caller_channel) == CS_EXECUTE &&
- switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
- !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
- ((time(NULL) - start) < timelimit)) {
- switch_yield(20000);
+ switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
+ !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
+ ((time(NULL) - start) < timelimit)) {
+ switch_yield(20000);
}
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &mod_bridgecall_module_interface;
{\r
struct g729_context *context = NULL;\r
int encoding, decoding;\r
- \r
+\r
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);\r
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);\r
- \r
+\r
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {\r
return SWITCH_STATUS_FALSE;\r
} else {\r
}\r
\r
codec->private = context;\r
- \r
+\r
return SWITCH_STATUS_SUCCESS;\r
}\r
}\r
\r
\r
static switch_status switch_g729_encode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *decoded_data,\r
- size_t decoded_data_len,\r
- int decoded_rate,\r
- void *encoded_data,\r
- size_t *encoded_data_len,\r
- int *encoded_rate,\r
- unsigned int *flag)\r
+ switch_codec *other_codec,\r
+ void *decoded_data,\r
+ size_t decoded_data_len,\r
+ int decoded_rate,\r
+ void *encoded_data,\r
+ size_t *encoded_data_len,\r
+ int *encoded_rate,\r
+ unsigned int *flag)\r
{\r
struct g729_context *context = codec->private;\r
int cbret = 0;\r
char *edp = encoded_data;\r
int x;\r
int loops = (int) decoded_data_len / 160;\r
- \r
+\r
for(x = 0; x < loops && new_len < *encoded_data_len; x++) {\r
g729_coder(&context->encoder_object, ddp, edp, &cbret);\r
edp += 10;\r
\r
\r
static switch_status switch_g729_decode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *encoded_data,\r
- size_t encoded_data_len,\r
- int encoded_rate,\r
- void *decoded_data,\r
- size_t *decoded_data_len,\r
- int *decoded_rate,\r
- unsigned int *flag) \r
+ switch_codec *other_codec,\r
+ void *encoded_data,\r
+ size_t encoded_data_len,\r
+ int encoded_rate,\r
+ void *decoded_data,\r
+ size_t *decoded_data_len,\r
+ int *decoded_rate,\r
+ unsigned int *flag) \r
{\r
struct g729_context *context = codec->private;\r
- \r
+\r
if (!context) {\r
return SWITCH_STATUS_FALSE;\r
}\r
} else {\r
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);\r
}\r
- \r
- \r
+\r
+\r
return SWITCH_STATUS_SUCCESS;\r
}\r
\r
switch_channel_hangup(channel);
return NULL;
}
-
+
while (switch_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "extensions")) {
if (!strcmp(var, caller_profile->destination_number) && val) {
memset(app, 0, sizeof(app));
strncpy(app, val, sizeof(app));
-
+
if ((data = strchr(app, ' '))) {
*data = '\0';
data++;
} else {
switch_channel_hangup(channel);
}
-
+
return extension;
}
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &demo_dialplan_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
-
-
-
break;
}
}
-
+
static switch_loadable_module_interface event_test_module_interface = {
/*.module_name*/ modname,
*
*/
-
#define HAVE_APR
#include <switch.h>
#include <jrtp4c.h>
free(globals.dialplan);
globals.dialplan = NULL;
}
-
+
globals.dialplan = strdup(dialplan);
}
}
switch (codec_type) {
- case SWITCH_CODEC_TYPE_AUDIO:
- med->m_media = osip_strdup("audio");
- osip_rfc3264_add_audio_media(cnf, med, -1);
- break;
- case SWITCH_CODEC_TYPE_VIDEO:
- med->m_media = osip_strdup("video");
- osip_rfc3264_add_video_media(cnf, med, -1);
- break;
- default:
- break;
+case SWITCH_CODEC_TYPE_AUDIO:
+ med->m_media = osip_strdup("audio");
+ osip_rfc3264_add_audio_media(cnf, med, -1);
+ break;
+case SWITCH_CODEC_TYPE_VIDEO:
+ med->m_media = osip_strdup("video");
+ osip_rfc3264_add_video_media(cnf, med, -1);
+ break;
+default:
+ break;
}
- return 0;
+ return 0;
}
/*
- State methods they get called when the state changes to the specific state
- returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
- so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
+State methods they get called when the state changes to the specific state
+returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
+so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/
static switch_status exosip_on_init(switch_core_session *session)
{
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
-
+
switch_set_flag(tech_pvt, TFLAG_BYE);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR;
}
-
+
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %s:%d->%s:%d codec: %d ms: %d\n",
- tech_pvt->local_sdp_audio_ip,
- tech_pvt->local_sdp_audio_port,
- tech_pvt->remote_sdp_audio_ip,
- tech_pvt->remote_sdp_audio_port,
- tech_pvt->read_codec.codec_interface->ianacode,
- ms
- );
+ tech_pvt->local_sdp_audio_ip,
+ tech_pvt->local_sdp_audio_port,
+ tech_pvt->remote_sdp_audio_ip,
+ tech_pvt->remote_sdp_audio_port,
+ tech_pvt->read_codec.codec_interface->ianacode,
+ ms
+ );
tech_pvt->rtp_session = jrtp4c_new(
- tech_pvt->local_sdp_audio_ip,
- tech_pvt->local_sdp_audio_port,
- tech_pvt->remote_sdp_audio_ip,
- tech_pvt->remote_sdp_audio_port,
- tech_pvt->read_codec.codec_interface->ianacode,
- tech_pvt->read_codec.implementation->samples_per_second,
- &err);
+ tech_pvt->local_sdp_audio_ip,
+ tech_pvt->local_sdp_audio_port,
+ tech_pvt->remote_sdp_audio_ip,
+ tech_pvt->remote_sdp_audio_port,
+ tech_pvt->read_codec.codec_interface->ianacode,
+ tech_pvt->read_codec.implementation->samples_per_second,
+ &err);
if (tech_pvt->rtp_session) {
tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session);
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
return SWITCH_STATUS_GENERR;
}
-
+
assert(tech_pvt->rtp_session != NULL);
tech_pvt->read_frame.datalen = 0;
while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session,
- tech_pvt->read_frame.data,
- sizeof(tech_pvt->read_buf));
+ tech_pvt->read_frame.data,
+ sizeof(tech_pvt->read_buf));
if (tech_pvt->read_frame.datalen > 0) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
tech_pvt->read_frame.samples = (int)samples;
break;
}
-
+
switch_yield(100);
}
//printf("%s %s->%s recv %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_ip, tech_pvt->read_frame.datalen, samples, frames, ms, tech_pvt->timestamp_recv);
-
+
//switch_mutex_unlock(tech_pvt->rtp_lock);
}
switch_clear_flag(tech_pvt, TFLAG_READING);
-
+
if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
*frame = &tech_pvt->read_frame;
-
+
return SWITCH_STATUS_SUCCESS;
}
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
return SWITCH_STATUS_GENERR;
}
} else {
assert(0);
}
-
-
+
+
//printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_set_flag(tech_pvt, TFLAG_BYE);
-
+
return SWITCH_STATUS_SUCCESS;
}
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
return SWITCH_STATUS_SUCCESS;
}
-
+
static const switch_io_routines exosip_io_routines = {
/*.outgoing_channel*/ exosip_outgoing_channel,
/*.answer_channel*/ exosip_answer_channel,
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &exosip_module_interface;
switch_core_session_destroy(&session);
return SWITCH_STATUS_MEMERR;
}
-
+
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- event->request->from->displayname,
- event->request->from->url->username,
- event->request->from->url->host,
- NULL,
- NULL,
- event->request->req_uri->username))) {
- switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
+ globals.dialplan,
+ event->request->from->displayname,
+ event->request->from->url->username,
+ event->request->from->url->host,
+ NULL,
+ NULL,
+ event->request->req_uri->username))) {
+ switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
switch_set_flag(tech_pvt, TFLAG_INBOUND);
snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
-
+
if (!(remote_sdp = eXosip_get_sdp_info(event->request))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n");
exosip_on_hangup(session);
tech_pvt->local_sdp_audio_port = next_rtp_port();
osip_rfc3264_init(&tech_pvt->sdp_config);
/* Add in what codecs we support locally */
-
+
if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
sdp_message_to_str(remote_sdp, &remote_sdp_str);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str);
-
+
mline = 0;
while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) {
snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr);
tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port);
-
+
snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid);
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_channel_hangup(channel);
- return SWITCH_STATUS_FALSE;
- } else {
- if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
+ } else {
+ if (switch_core_codec_init(&tech_pvt->write_codec,
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ switch_channel_hangup(channel);
+ return SWITCH_STATUS_FALSE;
} else {
int ms;
tech_pvt->read_frame.rate = rate;
}
}
}
-
+
activate_rtp(tech_pvt);
-
+
if (switch_test_flag(tech_pvt, TFLAG_RTP)) {
switch_core_session_thread_launch(session);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "destroy %s\n", switch_channel_get_name(channel));
exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL);
switch_channel_hangup(channel);
-
+
}
static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload)
/* Assign them thar IDs */
tech_pvt->did = event->did;
tech_pvt->tid = event->tid;
-
+
if (1) {
int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_channel_hangup(channel);
- return;
- } else {
- if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
+ } else {
+ if (switch_core_codec_init(&tech_pvt->write_codec,
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ switch_channel_hangup(channel);
+ return;
} else {
int ms;
tech_pvt->read_frame.rate = rate;
eXosip_call_build_ack(event->did, &ack);
eXosip_call_send_ack(event->did, ack);
eXosip_unlock();
-
+
free(dname);
free(drate);
free(dpayload);
} else if (je->type == EXOSIP_CALL_RELEASED) {
snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did);
} else if (je->type == EXOSIP_MESSAGE_NEW
- && je->request!=NULL && MSG_IS_MESSAGE(je->request)) {
- char *tmp = NULL;
-
- if (je->request != NULL) {
- osip_body_t *body;
- osip_from_to_str (je->request->from, &tmp);
-
- osip_message_get_body (je->request, 0, &body);
- if (body != NULL && body->body != NULL) {
- snprintf (buf, 99, "<- (%i) from: %s TEXT: %s",
- je->tid, tmp, body->body);
+ && je->request!=NULL && MSG_IS_MESSAGE(je->request)) {
+ char *tmp = NULL;
+
+ if (je->request != NULL) {
+ osip_body_t *body;
+ osip_from_to_str (je->request->from, &tmp);
+
+ osip_message_get_body (je->request, 0, &body);
+ if (body != NULL && body->body != NULL) {
+ snprintf (buf, 99, "<- (%i) from: %s TEXT: %s",
+ je->tid, tmp, body->body);
+ }
+ osip_free (tmp);
+ } else {
+ snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
}
- osip_free (tmp);
- } else {
- snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
- }
} else if (je->type == EXOSIP_MESSAGE_NEW) {
char *tmp = NULL;
-
+
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) %s from: %s",
- je->tid, je->request->sip_method, tmp);
+ je->tid, je->request->sip_method, tmp);
osip_free (tmp);
} else if (je->type == EXOSIP_MESSAGE_PROCEEDING
- || je->type == EXOSIP_MESSAGE_ANSWERED
- || je->type == EXOSIP_MESSAGE_REDIRECTED
- || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
- || je->type == EXOSIP_MESSAGE_SERVERFAILURE
- || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
- if (je->response != NULL && je->request != NULL) {
- char *tmp = NULL;
-
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s",
- je->tid, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
- } else if (je->request != NULL) {
- snprintf (buf, 99, "<- (%i) Error for %s request",
- je->tid, je->request->sip_method);
- } else {
- snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid);
- }
+ || je->type == EXOSIP_MESSAGE_ANSWERED
+ || je->type == EXOSIP_MESSAGE_REDIRECTED
+ || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
+ || je->type == EXOSIP_MESSAGE_SERVERFAILURE
+ || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
+ if (je->response != NULL && je->request != NULL) {
+ char *tmp = NULL;
+
+ osip_to_to_str (je->request->to, &tmp);
+ snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s",
+ je->tid, je->response->status_code,
+ je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free (tmp);
+ } else if (je->request != NULL) {
+ snprintf (buf, 99, "<- (%i) Error for %s request",
+ je->tid, je->request->sip_method);
+ } else {
+ snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid);
+ }
} else if (je->response == NULL && je->request != NULL && je->cid > 0) {
char *tmp = NULL;
-
+
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i %i) %s from: %s",
- je->cid, je->did, je->request->cseq->method, tmp);
+ je->cid, je->did, je->request->cseq->method, tmp);
osip_free (tmp);
} else if (je->response != NULL && je->cid > 0) {
char *tmp = NULL;
-
+
osip_to_to_str (je->request->to, &tmp);
snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
- je->cid, je->did, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
+ je->cid, je->did, je->response->status_code,
+ je->response->reason_phrase, je->request->sip_method, tmp);
osip_free (tmp);
} else if (je->response == NULL && je->request != NULL && je->rid > 0) {
char *tmp = NULL;
-
+
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) %s from: %s",
- je->rid, je->request->cseq->method, tmp);
+ je->rid, je->request->cseq->method, tmp);
osip_free (tmp);
} else if (je->response != NULL && je->rid > 0) {
char *tmp = NULL;
-
+
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->rid, je->response->status_code,
- je->response->reason_phrase, tmp);
+ je->rid, je->response->status_code,
+ je->response->reason_phrase, tmp);
osip_free (tmp);
} else if (je->response == NULL && je->request != NULL && je->sid > 0) {
char *tmp = NULL;
char *stat = NULL;
osip_header_t *sub_state;
-
+
osip_message_header_get_byname (je->request, "subscription-state",
- 0, &sub_state);
+ 0, &sub_state);
if (sub_state != NULL && sub_state->hvalue != NULL)
stat = sub_state->hvalue;
-
+
osip_uri_to_str (je->request->from->url, &tmp);
snprintf (buf, 99, "<- (%i) [%s] %s from: %s",
- je->sid, stat, je->request->cseq->method, tmp);
+ je->sid, stat, je->request->cseq->method, tmp);
osip_free (tmp);
} else if (je->response != NULL && je->sid > 0) {
char *tmp = NULL;
-
+
osip_uri_to_str (je->request->to->url, &tmp);
snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->sid, je->response->status_code,
- je->response->reason_phrase, tmp);
+ je->sid, je->response->status_code,
+ je->response->reason_phrase, tmp);
osip_free (tmp);
} else if (je->response == NULL && je->request != NULL) {
char *tmp = NULL;
-
+
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->request->sip_method, tmp);
+ je->cid, je->did, je->sid, je->nid,
+ je->request->sip_method, tmp);
osip_free (tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
-
+
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->response->status_code, je->response->reason_phrase,
- je->request->sip_method, tmp);
+ je->cid, je->did, je->sid, je->nid,
+ je->response->status_code, je->response->reason_phrase,
+ je->request->sip_method, tmp);
osip_free (tmp);
} else {
snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
- je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
+ je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf);
/* Print it out */
static void *monitor_thread_run(void)
{
eXosip_event_t *event = NULL;
-
+
globals.running = 1;
while (globals.running > 0) {
if (!(event = eXosip_event_wait(0,100))) {
log_event(event);
switch(event->type) {
- case EXOSIP_CALL_INVITE:
- exosip_create_call(event);
- break;
- case EXOSIP_CALL_REINVITE:
- /* See what the reinvite is about - on hold or whatever */
- //handle_reinvite(event);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n");
- break;
- case EXOSIP_CALL_MESSAGE_NEW:
- if (event->request != NULL && MSG_IS_REFER(event->request)) {
- //handle_call_transfer(event);
- }
- break;
- case EXOSIP_CALL_ACK:
- /* If audio is not flowing and this has SDP - fire it up! */
- break;
- case EXOSIP_CALL_ANSWERED:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n");
- handle_answer(event);
- break;
- case EXOSIP_CALL_PROCEEDING:
- /* This is like a 100 Trying... yeah */
- break;
- case EXOSIP_CALL_RINGING:
- //handle_ringing(event);
- break;
- case EXOSIP_CALL_REDIRECTED:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n");
- break;
- case EXOSIP_CALL_CLOSED:
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_RELEASED:
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_NOANSWER:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n");
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_REQUESTFAILURE:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n");
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_SERVERFAILURE:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n");
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_GLOBALFAILURE:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n");
- destroy_call_by_event(event);
- break;
- /* Registration related stuff */
- case EXOSIP_REGISTRATION_NEW:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n");
- break;
- default:
- /* Unknown event... casually absorb it for now */
- break;
+ case EXOSIP_CALL_INVITE:
+ exosip_create_call(event);
+ break;
+ case EXOSIP_CALL_REINVITE:
+ /* See what the reinvite is about - on hold or whatever */
+ //handle_reinvite(event);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n");
+ break;
+ case EXOSIP_CALL_MESSAGE_NEW:
+ if (event->request != NULL && MSG_IS_REFER(event->request)) {
+ //handle_call_transfer(event);
+ }
+ break;
+ case EXOSIP_CALL_ACK:
+ /* If audio is not flowing and this has SDP - fire it up! */
+ break;
+ case EXOSIP_CALL_ANSWERED:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n");
+ handle_answer(event);
+ break;
+ case EXOSIP_CALL_PROCEEDING:
+ /* This is like a 100 Trying... yeah */
+ break;
+ case EXOSIP_CALL_RINGING:
+ //handle_ringing(event);
+ break;
+ case EXOSIP_CALL_REDIRECTED:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n");
+ break;
+ case EXOSIP_CALL_CLOSED:
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_RELEASED:
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_NOANSWER:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n");
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_REQUESTFAILURE:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n");
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_SERVERFAILURE:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n");
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_GLOBALFAILURE:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n");
+ destroy_call_by_event(event);
+ break;
+ /* Registration related stuff */
+ case EXOSIP_REGISTRATION_NEW:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n");
+ break;
+ default:
+ /* Unknown event... casually absorb it for now */
+ break;
}
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo);
}
}
}
-
+
if (!globals.codec_ms) {
globals.codec_ms = 20;
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n");
return SWITCH_STATUS_GENERR;
}
-
+
switch_mutex_init(&globals.port_lock, SWITCH_MUTEX_NESTED, module_pool);
/* Setup the user agent */
static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
{
int encoding, decoding;
-
+
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
static switch_status switch_g711u_encode(switch_codec *codec,
- switch_codec *other_codec,
- void *decoded_data,
- size_t decoded_data_len,
- int decoded_rate,
- void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *decoded_data,
+ size_t decoded_data_len,
+ int decoded_rate,
+ void *encoded_data,
+ size_t *encoded_data_len,
+ int *encoded_rate,
+ unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
dbuf = decoded_data;
ebuf = encoded_data;
-
+
for (i = 0; i < decoded_data_len / sizeof(short); i++) {
ebuf[i] = linear2ulaw(dbuf[i]);
}
-
+
*encoded_data_len = i;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_g711u_decode(switch_codec *codec,
- switch_codec *other_codec,
- void *encoded_data,
- size_t encoded_data_len,
- int encoded_rate,
- void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *encoded_data,
+ size_t encoded_data_len,
+ int encoded_rate,
+ void *decoded_data,
+ size_t *decoded_data_len,
+ int *decoded_rate,
+ unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
{
int encoding, decoding;
-
+
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
static switch_status switch_g711a_encode(switch_codec *codec,
- switch_codec *other_codec,
- void *decoded_data,
- size_t decoded_data_len,
- int decoded_rate,
- void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *decoded_data,
+ size_t decoded_data_len,
+ int decoded_rate,
+ void *encoded_data,
+ size_t *encoded_data_len,
+ int *encoded_rate,
+ unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
dbuf = decoded_data;
ebuf = encoded_data;
-
+
for (i = 0; i < decoded_data_len / sizeof(short); i++) {
ebuf[i] = linear2alaw(dbuf[i]);
}
-
+
*encoded_data_len = i;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_g711a_decode(switch_codec *codec,
- switch_codec *other_codec,
- void *encoded_data,
- size_t encoded_data_len,
- int encoded_rate,
- void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *encoded_data,
+ size_t encoded_data_len,
+ int encoded_rate,
+ void *decoded_data,
+ size_t *decoded_data_len,
+ int *decoded_rate,
+ unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
struct private_object {
unsigned int flags;
switch_codec read_codec;
- switch_codec write_codec;
+ switch_codec write_codec;
struct switch_frame read_frame;
unsigned char databuf[1024];
switch_core_session *session;
break;
}
}
-
+
return ast;
}
if (globals.codec_string) {
if (!(num_codecs = loadable_module_get_codecs_sorted(switch_core_session_get_pool(tech_pvt->session),
- codecs,
- SWITCH_MAX_CODECS,
- globals.codec_order,
- globals.codec_order_last)) > 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
- return SWITCH_STATUS_GENERR;
+ codecs,
+ SWITCH_MAX_CODECS,
+ globals.codec_order,
+ globals.codec_order_last)) > 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
+ return SWITCH_STATUS_GENERR;
}
} else if (!(num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS)) > 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
}
local_cap |= codec;
}
-
+
if (io == IAX_SET) {
mixed_cap = (local_cap & *cababilities);
} else {
if (len) { /*they sent us a pref and we don't want to be codec master*/
char pref_str[256] = "(";
-
+
for (x = 0; x < len; x++) {
strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str));
strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str));
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec Prefs Detected: %s\n", pref_str);
-
+
for (x = 0; x < len; x++) {
if ((prefs[x] & mixed_cap)) {
int z;
switch_set_flag(tech_pvt, TFLAG_LINEAR);
}
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- 0,
- 0,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- return SWITCH_STATUS_GENERR;
+ dname,
+ 0,
+ 0,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ return SWITCH_STATUS_GENERR;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- 0,
- 0,
- 1,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_core_codec_destroy(&tech_pvt->read_codec);
- return SWITCH_STATUS_GENERR;
+ dname,
+ 0,
+ 0,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ switch_core_codec_destroy(&tech_pvt->read_codec);
+ return SWITCH_STATUS_GENERR;
} else {
int ms;
int rate;
/*
- State methods they get called when the state changes to the specific state
- returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
- so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
+State methods they get called when the state changes to the specific state
+returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
+so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/
static switch_status channel_on_init(switch_core_session *session)
{
iax_set_private(tech_pvt->iax_session, tech_pvt);
switch_set_flag(tech_pvt, TFLAG_IO);
-
+
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));
switch_mutex_lock(tech_pvt->mutex);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_core_codec_destroy(&tech_pvt->read_codec);
switch_core_codec_destroy(&tech_pvt->write_codec);
-
+
if (tech_pvt->iax_session) {
if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
iax_hangup(tech_pvt->iax_session, "Hangup");
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel);
switch_thread_cond_signal(tech_pvt->cond);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
-
+
return SWITCH_STATUS_SUCCESS;
}
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
- that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
+that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
{
iax_call(tech_pvt->iax_session,
- caller_profile->caller_id_number,
- caller_profile->caller_id_name,
- caller_profile->destination_number,
- NULL, 0, req, cap);
+ caller_profile->caller_id_number,
+ caller_profile->caller_id_name,
+ caller_profile->destination_number,
+ NULL, 0, req, cap);
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
}
}
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags)
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
return SWITCH_STATUS_FALSE;
}
-
+
if (switch_test_flag(tech_pvt, TFLAG_IO)) {
switch_clear_flag(tech_pvt, TFLAG_VOICE);
if(!tech_pvt->read_frame.datalen) {
continue;
}
-
+
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
}
iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int)frame->datalen, tech_pvt->write_codec.implementation->samples_per_frame);
return SWITCH_STATUS_SUCCESS;
-
+
}
static switch_status channel_answer_channel(switch_core_session *session)
switch_config cfg;
char *var, *val;
char *cf = "iax.conf";
-
+
memset(&globals, 0, sizeof(globals));
-
+
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
-
+
while (switch_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "settings")) {
if (!strcmp(var, "debug")) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Binding Port!\n");
return SWITCH_STATUS_TERM;
}
-
+
iax_set_error(iax_err_cb);
- iax_set_output(iax_out_cb);
- netfd = iax_get_fd();
-
+ iax_set_output(iax_out_cb);
+ netfd = iax_get_fd();
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "IAX Ready Port %d\n", globals.port);
-
+
for(;;) {
if (running == -1) {
if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Event %d [%s]!\n",
- iaxevent->etype, IAXNAMES[iaxevent->etype]);
+ iaxevent->etype, IAXNAMES[iaxevent->etype]);
}
switch (iaxevent->etype) {
- case IAX_EVENT_REGACK:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n");
- if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh;
- break;
- case IAX_EVENT_REGREJ:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n");
- break;
- case IAX_EVENT_TIMEOUT:
- break;
- case IAX_EVENT_ACCEPT:
- if (tech_pvt) {
- unsigned int cap = iax_session_get_capability(iaxevent->session);
- unsigned int format = iaxevent->ies.format;
-
- if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, IAX_SET) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n",iaxevent->ies.format, iaxevent->ies.capability);
- }
- }
-
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n");
- break;
- case IAX_EVENT_RINGA:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n");
- break;
- case IAX_EVENT_PONG:
- // informative only
- break;
- case IAX_EVENT_ANSWER:
- // the other side answered our call
- if (tech_pvt) {
- switch_channel *channel;
- if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", switch_channel_get_name(channel));
- switch_channel_answer(channel);
+ case IAX_EVENT_REGACK:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n");
+ if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh;
+ break;
+ case IAX_EVENT_REGREJ:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n");
+ break;
+ case IAX_EVENT_TIMEOUT:
+ break;
+ case IAX_EVENT_ACCEPT:
+ if (tech_pvt) {
+ unsigned int cap = iax_session_get_capability(iaxevent->session);
+ unsigned int format = iaxevent->ies.format;
+
+ if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, IAX_SET) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n",iaxevent->ies.format, iaxevent->ies.capability);
+ }
}
- }
- break;
- case IAX_EVENT_CONNECT:
- // incoming call detected
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,
- "Incoming call connected %s, %s, %s %d/%d\n",
- iaxevent->ies.called_number,
- iaxevent->ies.calling_number,
- iaxevent->ies.calling_name,
- iaxevent->ies.format,
- iaxevent->ies.capability);
-
- if (iaxevent) {
- switch_core_session *session;
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name);
- if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
- struct private_object *tech_pvt;
- switch_channel *channel;
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
- memset(tech_pvt, 0, sizeof(*tech_pvt));
- channel = switch_core_session_get_channel(session);
- switch_core_session_set_private(session, tech_pvt);
- tech_pvt->session = session;
- } else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n");
- switch_core_session_destroy(&session);
- break;
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n");
+ break;
+ case IAX_EVENT_RINGA:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n");
+ break;
+ case IAX_EVENT_PONG:
+ // informative only
+ break;
+ case IAX_EVENT_ANSWER:
+ // the other side answered our call
+ if (tech_pvt) {
+ switch_channel *channel;
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", switch_channel_get_name(channel));
+ switch_channel_answer(channel);
}
+ }
-
- if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- iaxevent->ies.calling_name,
- iaxevent->ies.calling_number,
- iax_get_peer_ip(iaxevent->session),
- iaxevent->ies.calling_ani,
- NULL,
- iaxevent->ies.called_number))) {
- char name[128];
- switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
- snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
- switch_channel_set_name(channel, name);
+ break;
+ case IAX_EVENT_CONNECT:
+ // incoming call detected
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE,
+ "Incoming call connected %s, %s, %s %d/%d\n",
+ iaxevent->ies.called_number,
+ iaxevent->ies.calling_number,
+ iaxevent->ies.calling_name,
+ iaxevent->ies.format,
+ iaxevent->ies.capability);
+
+ if (iaxevent) {
+ switch_core_session *session;
+
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name);
+ if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
+ struct private_object *tech_pvt;
+ switch_channel *channel;
+
+ if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
+ memset(tech_pvt, 0, sizeof(*tech_pvt));
+ channel = switch_core_session_get_channel(session);
+ switch_core_session_set_private(session, tech_pvt);
+ tech_pvt->session = session;
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n");
+ switch_core_session_destroy(&session);
+ break;
+ }
+
+
+ if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
+ globals.dialplan,
+ iaxevent->ies.calling_name,
+ iaxevent->ies.calling_number,
+ iax_get_peer_ip(iaxevent->session),
+ iaxevent->ies.calling_ani,
+ NULL,
+ iaxevent->ies.called_number))) {
+ char name[128];
+ switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
+ snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
+ switch_channel_set_name(channel, name);
+ }
+
+ if (iax_set_codec(tech_pvt, iaxevent->session,
+ &iaxevent->ies.format,
+ &iaxevent->ies.capability,
+ IAX_SET) != SWITCH_STATUS_SUCCESS) {
+ iax_reject(iaxevent->session, "Codec Error!");
+ switch_core_session_destroy(&session);
+ } else {
+ tech_pvt->iax_session = iaxevent->session;
+ tech_pvt->session = session;
+ iax_accept(tech_pvt->iax_session, tech_pvt->codec);
+ iax_ring_announce(tech_pvt->iax_session);
+ switch_channel_set_state(channel, CS_INIT);
+ switch_core_session_thread_launch(session);
+ }
}
+ }
+ break;
+ case IAX_EVENT_REJECT:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n");
+ case IAX_EVENT_BUSY:
+ case IAX_EVENT_HANGUP:
+ if (tech_pvt) {
+ switch_channel *channel;
- if (iax_set_codec(tech_pvt, iaxevent->session,
- &iaxevent->ies.format,
- &iaxevent->ies.capability,
- IAX_SET) != SWITCH_STATUS_SUCCESS) {
- iax_reject(iaxevent->session, "Codec Error!");
- switch_core_session_destroy(&session);
+ switch_clear_flag(tech_pvt, TFLAG_IO);
+ switch_clear_flag(tech_pvt, TFLAG_VOICE);
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel));
+ switch_set_flag(tech_pvt, TFLAG_HANGUP);
+ switch_channel_hangup(channel);
+ switch_thread_cond_signal(tech_pvt->cond);
+ iaxevent->session = NULL;
} else {
- tech_pvt->iax_session = iaxevent->session;
- tech_pvt->session = session;
- iax_accept(tech_pvt->iax_session, tech_pvt->codec);
- iax_ring_announce(tech_pvt->iax_session);
- switch_channel_set_state(channel, CS_INIT);
- switch_core_session_thread_launch(session);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
}
}
- }
- break;
- case IAX_EVENT_REJECT:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n");
- case IAX_EVENT_BUSY:
- case IAX_EVENT_HANGUP:
- if (tech_pvt) {
- switch_channel *channel;
-
- switch_clear_flag(tech_pvt, TFLAG_IO);
- switch_clear_flag(tech_pvt, TFLAG_VOICE);
- if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel));
- switch_set_flag(tech_pvt, TFLAG_HANGUP);
- switch_channel_hangup(channel);
+ break;
+ case IAX_EVENT_CNG:
+ // pseudo-silence
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n");
+ break;
+ case IAX_EVENT_VOICE:
+ if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) {
+ int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
+ int frames = (int)(tech_pvt->read_frame.datalen / bytes);
+ tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
+ memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
+ /* wake up the i/o thread*/
+ switch_set_flag(tech_pvt, TFLAG_VOICE);
switch_thread_cond_signal(tech_pvt->cond);
- iaxevent->session = NULL;
- } else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
- }
- }
- break;
- case IAX_EVENT_CNG:
- // pseudo-silence
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n");
- break;
- case IAX_EVENT_VOICE:
- if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) {
- int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- int frames = (int)(tech_pvt->read_frame.datalen / bytes);
- tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
- memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
- /* wake up the i/o thread*/
- switch_set_flag(tech_pvt, TFLAG_VOICE);
- switch_thread_cond_signal(tech_pvt->cond);
- }
- break;
- case IAX_EVENT_TRANSFER:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n");
- //session[0] = iaxevent->session;
- break;
- case IAX_EVENT_DTMF:
- if (tech_pvt) {
- switch_channel *channel;
- if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
- char str[2] = {iaxevent->subclass};
- if (globals.debug) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, switch_channel_get_name(channel));
+ }
+ break;
+ case IAX_EVENT_TRANSFER:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n");
+ //session[0] = iaxevent->session;
+ break;
+ case IAX_EVENT_DTMF:
+ if (tech_pvt) {
+ switch_channel *channel;
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
+ char str[2] = {iaxevent->subclass};
+ if (globals.debug) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, switch_channel_get_name(channel));
+ }
+ switch_channel_queue_dtmf(channel, str);
}
- switch_channel_queue_dtmf(channel, str);
}
- }
- break;
- default:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype);
- break;
+ break;
+ default:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype);
+ break;
}
-
+
iax_event_free(iaxevent);
}
}
-
+
running = 0;
return SWITCH_STATUS_TERM;
assert(channel != NULL);
if (switch_core_file_open(&fh,
- data,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
- switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_channel_hangup(channel);
- return;
+ data,
+ SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ switch_channel_hangup(channel);
+ return;
}
switch_channel_answer(channel);
write_frame.data = buf;
write_frame.buflen = sizeof(buf);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s %dhz %d channels\n", data, fh.samplerate, fh.channels);
-
+
interval = 20;
samples = (fh.samplerate / 50) * fh.channels;
len = samples * 2;
-
+
codec_name = "L16";
-
+
if (switch_core_codec_init(&codec,
- codec_name,
- fh.samplerate,
- interval,
- fh.channels,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- pool) == SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
- write_frame.codec = &codec;
+ codec_name,
+ fh.samplerate,
+ interval,
+ fh.channels,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ pool) == SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
+ write_frame.codec = &codec;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", codec_name, fh.samplerate, fh.channels, interval);
switch_core_file_close(&fh);
if (switch_channel_has_dtmf(channel)) {
switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF [%s]\n", dtmf);
-
+
switch (*dtmf) {
case '*':
done = 1;
break;
}
}
-
+
if (done) {
break;
}
-
+
switch_core_file_read(&fh, buf, &ilen);
if (ilen <= 0) {
break;
}
-
+
write_frame.datalen = ilen * 2;
write_frame.samples = (int)ilen;
#ifdef SWAP_LINEAR
break;
}
}
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "done playing file\n");
switch_core_file_close(&fh);
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &mod_playback_module_interface;
}
/* 'switch_module_runtime' will start up in a thread by itself just by having it exist
- if it returns anything but SWITCH_STATUS_TERM it will be called again automaticly
- */
+if it returns anything but SWITCH_STATUS_TERM it will be called again automaticly
+*/
//switch_status switch_module_runtime(void)
return SWITCH_STATUS_SUCCESS;
}
-#if 0
-switch_status raw_file_open(switch_file_handle *handle, char *path)
-{
- return SWITCH_STATUS_SUCCESS;
-}
-
-switch_status raw_file_close(switch_file_handle *handle)
-{
- return SWITCH_STATUS_SUCCESS;
-}
-
-switch_status raw_file_seek(switch_file_handle *handle, unsigned int *cur_sample, unsigned int samples, int whence)
-{
- return SWITCH_STATUS_NOTIMPL;
-}
-
-
-/* Registration */
-
-
-static char *supported_formats[] = {"raw", "r8k", NULL};
-
-static const switch_file_interface raw_file_interface = {
- /*.interface_name*/ "raw",
- /*.file_open*/ raw_file_open,
- /*.file_close*/ raw_file_close,
- /*.file_read*/ NULL,
- /*.file_write*/ NULL,
- /*.file_seek*/ raw_file_seek,
- /*.extens*/ supported_formats,
- /*.next*/ NULL,
-};
-#endif
-
static const switch_codec_implementation raw_32k_implementation = {
/*.samples_per_second = */ 32000,
/*.bits_per_second = */ 512000,
struct woomera_profile *profile;
char dest[WOOMERA_STRLEN];
int port;
- struct timeval started;
+ switch_time_t started;
int timeout;
char dtmfbuf[WOOMERA_STRLEN];
switch_caller_profile *caller_profile;
}
SWITCH_DECLARE(switch_status) switch_channel_init(switch_channel *channel,
- switch_core_session *session,
- switch_channel_state state,
- switch_channel_flag flags)
+ switch_core_session *session,
+ switch_channel_state state,
+ switch_channel_flag flags)
{
assert(channel != NULL);
channel->state = state;
/* STUB for more dev
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(state) {
- 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;
+ case CS_DONE:
default:
- break;
+ 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;
}
caller_profile = switch_channel_get_caller_profile(channel);
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-Name", switch_channel_get_name(channel));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
if (caller_profile) {
switch_caller_profile_event_set_data(caller_profile, "Caller", event);
}
-
+
/* Index Originator's Profile */
if (originator_caller_profile) {
switch_caller_profile_event_set_data(originator_caller_profile, "Originator", event);
static int switch_console_process(char *cmd)
{
-char *arg = NULL;
- char retbuf[1024] = "";
+ char *arg = NULL;
+ char retbuf[1024] = "";
#ifdef EMBED_PERL
const char *perlhelp = "perl - execute some perl. (print to STDERR if you want to see it.)\n";
}
if (!strcmp(cmd, "help")) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
- "\n"
- "Valid Commands:\n\n"
- "help - umm yeah..\n"
- "%sshutdown - stop the program\n\n",
- perlhelp
- );
+ "\n"
+ "Valid Commands:\n\n"
+ "help - umm yeah..\n"
+ "%sshutdown - stop the program\n\n",
+ perlhelp
+ );
return 1;
}
}
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_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_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);
}
free(data);
}
{
switch_core_db *db;
char path[1024];
-
+
db_pick_path(filename, path, sizeof(path));
if (switch_core_db_open(path, &db)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
FILE *handle = stdout;
switch (channel) {
- case SWITCH_CHANNEL_ID_CONSOLE:
- case SWITCH_CHANNEL_ID_CONSOLE_CLEAN:
- handle = runtime.console;
- break;
- default:
- handle = stdout;
- break;
+case SWITCH_CHANNEL_ID_CONSOLE:
+case SWITCH_CHANNEL_ID_CONSOLE_CLEAN:
+ handle = runtime.console;
+ break;
+default:
+ handle = stdout;
+ break;
}
return handle;
if ((!rate || rate == iptr->samples_per_second) &&
(!ms || ms == (iptr->microseconds_per_frame / 1000)) &&
(!channels || channels == iptr->number_of_channels)) {
- implementation = iptr;
- break;
+ implementation = iptr;
+ break;
}
}
}
SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
- switch_codec *other_codec,
- void *decoded_data,
- size_t decoded_data_len,
- int decoded_rate,
- void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *decoded_data,
+ size_t decoded_data_len,
+ int decoded_rate,
+ void *encoded_data,
+ size_t *encoded_data_len,
+ int *encoded_rate,
+ unsigned int *flag)
{
assert(codec != NULL);
assert(encoded_data != NULL);
}
SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
- switch_codec *other_codec,
- void *encoded_data,
- size_t encoded_data_len,
- int encoded_rate,
- void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *encoded_data,
+ size_t encoded_data_len,
+ int encoded_rate,
+ void *decoded_data,
+ size_t *decoded_data_len,
+ int *decoded_rate,
+ unsigned int *flag)
{
assert(codec != NULL);
assert(encoded_data != NULL);
memset(fh, 0, sizeof(*fh));
if (!(ext = strrchr(file_path, '.'))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n");
return SWITCH_STATUS_FALSE;
}
ext++;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "invalid file format [%s]!\n", ext);
return SWITCH_STATUS_GENERR;
}
-
+
fh->flags = flags;
if (pool) {
fh->memory_pool = pool;
} else {
if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
- return status;
- }
- switch_set_flag(fh, SWITCH_TIMER_FLAG_FREE_POOL);
+ return status;
+ }
+ switch_set_flag(fh, SWITCH_TIMER_FLAG_FREE_POOL);
}
return fh->file_interface->file_open(fh, file_path);
SWITCH_DECLARE(switch_status) switch_core_file_read(switch_file_handle *fh, void *data, size_t *len)
{
assert(fh != NULL);
-
+
return fh->file_interface->file_read(fh, data, 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, len);
}
while(data->running > 0) {
switch(switch_core_session_read_frame(session, &read_frame, -1)) {
- case SWITCH_STATUS_SUCCESS:
- break;
- case SWITCH_STATUS_TIMEOUT:
- break;
- default:
- data->running = -1;
- continue;
- break;
+case SWITCH_STATUS_SUCCESS:
+ break;
+case SWITCH_STATUS_TIMEOUT:
+ break;
+default:
+ data->running = -1;
+ continue;
+ break;
}
switch_yield(100);
}
/* **ONLY** alloc things with this function that **WILL NOT** outlive
- the session itself or expect an earth shattering KABOOM!*/
+the session itself or expect an earth shattering KABOOM!*/
SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory)
{
void *ptr = NULL;
}
/* **ONLY** alloc things with these functions that **WILL NOT** need
- to be freed *EVER* ie this is for *PERMENANT* memory allocation */
+to be freed *EVER* ie this is for *PERMENANT* memory allocation */
SWITCH_DECLARE(void *) switch_core_permenant_alloc(size_t memory)
{
}
SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_session *session,
- char *endpoint_name,
- switch_caller_profile *caller_profile,
- switch_core_session **new_session)
+ char *endpoint_name,
+ switch_caller_profile *caller_profile,
+ switch_core_session **new_session)
{
struct switch_io_event_hook_outgoing_channel *ptr;
switch_status status = SWITCH_STATUS_FALSE;
unsigned int flag = 0;
session->raw_read_frame.datalen = session->raw_read_frame.buflen;
status = switch_core_codec_decode(read_frame->codec,
- session->read_codec,
- read_frame->data,
- read_frame->datalen,
- read_frame->rate,
- session->raw_read_frame.data,
- &session->raw_read_frame.datalen,
- &session->raw_read_frame.rate,
- &flag);
+ session->read_codec,
+ read_frame->data,
+ read_frame->datalen,
+ read_frame->rate,
+ session->raw_read_frame.data,
+ &session->raw_read_frame.datalen,
+ &session->raw_read_frame.rate,
+ &flag);
switch (status) {
- case SWITCH_STATUS_RESAMPLE:
- if (!session->read_resampler) {
- switch_resample_create(&session->read_resampler,
- read_frame->codec->implementation->samples_per_second,
- read_frame->codec->implementation->bytes_per_frame * 10,
- session->read_codec->implementation->samples_per_second,
- session->read_codec->implementation->bytes_per_frame * 10,
- session->pool);
- }
- case SWITCH_STATUS_SUCCESS:
- read_frame = &session->raw_read_frame;
- break;
- case SWITCH_STATUS_NOOP:
- status = SWITCH_STATUS_SUCCESS;
- break;
- default:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
- return status;
- break;
+case SWITCH_STATUS_RESAMPLE:
+ if (!session->read_resampler) {
+ switch_resample_create(&session->read_resampler,
+ read_frame->codec->implementation->samples_per_second,
+ read_frame->codec->implementation->bytes_per_frame * 10,
+ session->read_codec->implementation->samples_per_second,
+ session->read_codec->implementation->bytes_per_frame * 10,
+ session->pool);
+ }
+case SWITCH_STATUS_SUCCESS:
+ read_frame = &session->raw_read_frame;
+ break;
+case SWITCH_STATUS_NOOP:
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+default:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
+ return status;
+ break;
}
}
if (session->read_resampler) {
enc_frame = *frame;
} 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->raw_read_frame.data,
+ 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;
}
session->enc_read_frame.datalen = session->enc_read_frame.buflen;
status = switch_core_codec_encode(session->read_codec,
- (*frame)->codec,
- session->raw_read_frame.data,
- session->raw_read_frame.datalen,
- session->raw_read_frame.rate,
- session->enc_read_frame.data,
- &session->enc_read_frame.datalen,
- &session->enc_read_frame.rate,
- &flag);
+ (*frame)->codec,
+ session->raw_read_frame.data,
+ session->raw_read_frame.datalen,
+ session->raw_read_frame.rate,
+ session->enc_read_frame.data,
+ &session->enc_read_frame.datalen,
+ &session->enc_read_frame.rate,
+ &flag);
switch (status) {
- case SWITCH_STATUS_SUCCESS:
- *frame = &session->enc_read_frame;
- break;
- case SWITCH_STATUS_NOOP:
- *frame = &session->raw_read_frame;
- status = SWITCH_STATUS_SUCCESS;
- break;
- default:
- 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;
+case SWITCH_STATUS_SUCCESS:
+ *frame = &session->enc_read_frame;
+ break;
+case SWITCH_STATUS_NOOP:
+ *frame = &session->raw_read_frame;
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+default:
+ 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;
}
}
}
if (frame->codec) {
session->raw_write_frame.datalen = session->raw_write_frame.buflen;
status = switch_core_codec_decode(frame->codec,
- session->write_codec,
- frame->data,
- frame->datalen,
- frame->rate,
- session->raw_write_frame.data,
- &session->raw_write_frame.datalen,
- &session->raw_write_frame.rate,
- &flag);
+ session->write_codec,
+ frame->data,
+ frame->datalen,
+ frame->rate,
+ session->raw_write_frame.data,
+ &session->raw_write_frame.datalen,
+ &session->raw_write_frame.rate,
+ &flag);
switch (status) {
- case SWITCH_STATUS_RESAMPLE:
- write_frame = &session->raw_write_frame;
- if (!session->write_resampler) {
- status = switch_resample_create(&session->write_resampler,
- frame->codec->implementation->samples_per_second,
- frame->codec->implementation->bytes_per_frame * 10,
- session->write_codec->implementation->samples_per_second,
- session->write_codec->implementation->bytes_per_frame * 10,
- session->pool);
- }
- break;
- case SWITCH_STATUS_SUCCESS:
- write_frame = &session->raw_write_frame;
- break;
- case SWITCH_STATUS_NOOP:
- write_frame = frame;
- status = SWITCH_STATUS_SUCCESS;
- break;
- default:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
- return status;
- break;
+case SWITCH_STATUS_RESAMPLE:
+ write_frame = &session->raw_write_frame;
+ if (!session->write_resampler) {
+ status = switch_resample_create(&session->write_resampler,
+ frame->codec->implementation->samples_per_second,
+ frame->codec->implementation->bytes_per_frame * 10,
+ session->write_codec->implementation->samples_per_second,
+ session->write_codec->implementation->bytes_per_frame * 10,
+ session->pool);
+ }
+ break;
+case SWITCH_STATUS_SUCCESS:
+ write_frame = &session->raw_write_frame;
+ break;
+case SWITCH_STATUS_NOOP:
+ write_frame = frame;
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+default:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
+ return status;
+ break;
}
}
if (session->write_resampler) {
if (!session->raw_write_buffer) {
int bytes = session->write_codec->implementation->bytes_per_frame * 10;
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);
+ "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) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n");
return status;
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
status = switch_core_codec_encode(session->write_codec,
- frame->codec,
- enc_frame->data,
- enc_frame->datalen,
- enc_frame->rate,
- session->enc_write_frame.data,
- &session->enc_write_frame.datalen,
- &session->enc_write_frame.rate,
- &flag);
+ frame->codec,
+ enc_frame->data,
+ enc_frame->datalen,
+ enc_frame->rate,
+ session->enc_write_frame.data,
+ &session->enc_write_frame.datalen,
+ &session->enc_write_frame.rate,
+ &flag);
switch (status) {
- case SWITCH_STATUS_SUCCESS:
- write_frame = &session->enc_write_frame;
- break;
- case SWITCH_STATUS_NOOP:
- write_frame = enc_frame;
- status = SWITCH_STATUS_SUCCESS;
- break;
- default:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
- write_frame = NULL;
- return status;
- break;
+case SWITCH_STATUS_SUCCESS:
+ write_frame = &session->enc_write_frame;
+ break;
+case SWITCH_STATUS_NOOP:
+ write_frame = enc_frame;
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+default:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
+ write_frame = NULL;
+ return status;
+ break;
}
status = perform_write(session, write_frame, timeout, io_flag);
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))) {
-
- enc_frame = &session->raw_write_frame;
- session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
- session->enc_write_frame.datalen = session->enc_write_frame.buflen;
- status = switch_core_codec_encode(session->write_codec,
- frame->codec,
- enc_frame->data,
- enc_frame->datalen,
- enc_frame->rate,
- session->enc_write_frame.data,
- &session->enc_write_frame.datalen,
- &session->enc_write_frame.rate,
- &flag);
-
-
-
- switch (status) {
- case SWITCH_STATUS_SUCCESS:
- write_frame = &session->enc_write_frame;
- break;
- case SWITCH_STATUS_NOOP:
- write_frame = enc_frame;
- status = SWITCH_STATUS_SUCCESS;
- break;
- default:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
- write_frame = NULL;
- return status;
- break;
- }
- status = perform_write(session, write_frame, timeout, io_flag);
+ 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;
+ session->enc_write_frame.datalen = session->enc_write_frame.buflen;
+ status = switch_core_codec_encode(session->write_codec,
+ frame->codec,
+ enc_frame->data,
+ enc_frame->datalen,
+ enc_frame->rate,
+ session->enc_write_frame.data,
+ &session->enc_write_frame.datalen,
+ &session->enc_write_frame.rate,
+ &flag);
+
+
+
+ switch (status) {
+case SWITCH_STATUS_SUCCESS:
+ write_frame = &session->enc_write_frame;
+ break;
+case SWITCH_STATUS_NOOP:
+ write_frame = enc_frame;
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+default:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
+ write_frame = NULL;
+ return status;
+ break;
+ }
+ status = perform_write(session, write_frame, timeout, io_flag);
}
}
return status;
static void switch_core_standard_on_hangup(switch_core_session *session)
{
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard HANGUP %s\n", switch_channel_get_name(session->channel));
}
}
}
}
- }
+}
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,
- extension->current_application->application_data);
+ extension->current_application->application_data);
if (!(application_interface = 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);
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.
*/
}
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 */
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n");
- if (!driver_event_handlers->on_hangup ||
- (driver_event_handlers->on_hangup &&
- driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- if (!application_event_handlers || !application_event_handlers->on_hangup ||
- (application_event_handlers->on_hangup &&
- application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- switch_core_standard_on_hangup(session);
- }
- }
- switch_channel_set_state(session->channel, CS_DONE);
- break;
- 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 &&
- driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- if (!application_event_handlers || !application_event_handlers->on_init ||
- (application_event_handlers->on_init &&
- application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- switch_core_standard_on_init(session);
- }
- }
- break;
- 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 &&
- driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- if (!application_event_handlers || !application_event_handlers->on_ring ||
- (application_event_handlers->on_ring &&
- application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- switch_core_standard_on_ring(session);
- }
- }
- break;
- 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 &&
- driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- if (!application_event_handlers || !application_event_handlers->on_execute ||
- (application_event_handlers->on_execute &&
- application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- switch_core_standard_on_execute(session);
- }
- }
- break;
- 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 &&
- driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- if (!application_event_handlers || !application_event_handlers->on_loopback ||
- (application_event_handlers->on_loopback &&
- application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- switch_core_standard_on_loopback(session);
- }
- }
- break;
- 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 &&
- driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- if (!application_event_handlers || !application_event_handlers->on_transmit ||
- (application_event_handlers->on_transmit &&
- application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
- midstate == switch_channel_get_state(session->channel))) {
- switch_core_standard_on_transmit(session);
- }
- }
- break;
+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 */
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n");
+ if (!driver_event_handlers->on_hangup ||
+ (driver_event_handlers->on_hangup &&
+ driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ if (!application_event_handlers || !application_event_handlers->on_hangup ||
+ (application_event_handlers->on_hangup &&
+ application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ switch_core_standard_on_hangup(session);
+ }
+ }
+ switch_channel_set_state(session->channel, CS_DONE);
+ break;
+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 &&
+ driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ if (!application_event_handlers || !application_event_handlers->on_init ||
+ (application_event_handlers->on_init &&
+ application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ switch_core_standard_on_init(session);
+ }
+ }
+ break;
+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 &&
+ driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ if (!application_event_handlers || !application_event_handlers->on_ring ||
+ (application_event_handlers->on_ring &&
+ application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ switch_core_standard_on_ring(session);
+ }
+ }
+ break;
+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 &&
+ driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ if (!application_event_handlers || !application_event_handlers->on_execute ||
+ (application_event_handlers->on_execute &&
+ application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ switch_core_standard_on_execute(session);
+ }
+ }
+ break;
+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 &&
+ driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ if (!application_event_handlers || !application_event_handlers->on_loopback ||
+ (application_event_handlers->on_loopback &&
+ application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ switch_core_standard_on_loopback(session);
+ }
+ }
+ break;
+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 &&
+ driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ if (!application_event_handlers || !application_event_handlers->on_transmit ||
+ (application_event_handlers->on_transmit &&
+ application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
+ midstate == switch_channel_get_state(session->channel))) {
+ switch_core_standard_on_transmit(session);
+ }
+ }
+ break;
}
laststate = midstate;
}
/* This function abstracts the thread creation for modules by allowing you to pass a function ptr and
- a void object and trust that that the function will be run in a thread with arg This lets
- you request and activate a thread without giving up any knowledge about what is in the thread
- neither the core nor the calling module know anything about each other.
+a void object and trust that that the function will be run in a thread with arg This lets
+you request and activate a thread without giving up any knowledge about what is in the thread
+neither the core nor the calling module know anything about each other.
- This thread is expected to never exit until the application exits so the func is responsible
- to make sure that is the case.
+This thread is expected to never exit until the application exits so the func is responsible
+to make sure that is the case.
- The typical use for this is so switch_loadable_module.c can start up a thread for each module
- passing the table of module methods as a session obj into the core without actually allowing
- the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
+The typical use for this is so switch_loadable_module.c can start up a thread for each module
+passing the table of module methods as a session obj into the core without actually allowing
+the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
*/
switch_threadattr_detach_set(thd_attr, 1);
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
- return;
- }
-
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
+ return;
+ }
+
if (!(ts = switch_core_alloc(pool, sizeof(*ts)))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory\n");
} else {
ts->objs[0] = obj;
switch_thread_create(&thread,
- thd_attr,
- func,
- ts,
- ts->pool
- );
+ thd_attr,
+ func,
+ ts,
+ ts->pool
+ );
}
}
switch_threadattr_detach_set(thd_attr, 1);
if (switch_thread_create(&thread,
- thd_attr,
- switch_core_session_thread,
- session,
- session->pool
- ) != APR_SUCCESS) {
- switch_core_session_destroy(&session);
+ thd_attr,
+ switch_core_session_thread,
+ session,
+ session->pool
+ ) != APR_SUCCESS) {
+ switch_core_session_destroy(&session);
}
}
switch_threadattr_detach_set(thd_attr, 1);
switch_thread_create(&thread,
- thd_attr,
- func,
- obj,
- session->pool
- );
+ thd_attr,
+ func,
+ obj,
+ session->pool
+ );
}
switch_channel_init(session->channel, session, CS_NEW, CF_SEND_AUDIO | CF_RECV_AUDIO);
/* The session *IS* the pool you may not alter it because you have no idea how
- its all private it will be passed to the thread run function */
+ its all private it will be passed to the thread run function */
switch_uuid_get(&uuid);
switch_uuid_format(session->uuid_str, &uuid);
session->raw_write_frame.buflen = sizeof(session->raw_write_buf);
session->raw_read_frame.data = session->raw_read_buf;
session->raw_read_frame.buflen = sizeof(session->raw_read_buf);
-
+
session->enc_write_frame.data = session->enc_write_buf;
session->enc_write_frame.buflen = sizeof(session->enc_write_buf);
switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED ,session->pool);
switch_thread_cond_create(&session->cond, session->pool);
-
+
return session;
}
char buf[1024];
switch(event->event_id) {
- case SWITCH_EVENT_LOG:
- return;
- break;
- default:
- switch_event_serialize(event, buf, sizeof(buf), NULL);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
- break;
+case SWITCH_EVENT_LOG:
+ return;
+ break;
+default:
+ switch_event_serialize(event, buf, sizeof(buf), NULL);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
+ break;
}
}
dup = switch_core_strdup(THRUNTIME_POOL, str);
switch_mutex_unlock(POOL_LOCK);
/* </LOCKED> ----------------------------------------------*/
-
+
return dup;
}
#define ALLOC(size) locked_alloc(size)
#endif
/* make sure this is synced with the switch_event_t enum in switch_types.h
- also never put any new ones before EVENT_ALL
+also never put any new ones before EVENT_ALL
*/
static char *EVENT_NAMES[] = {
"CUSTOM",
{
int match = 0;
-
+
if (node->event_id == SWITCH_EVENT_ALL) {
match++;
node->callback(out_event);
}
}
-
+
if (e == SWITCH_EVENT_ALL) {
break;
}
subclass->owner = switch_core_strdup(RUNTIME_POOL, owner);
subclass->name = switch_core_strdup(RUNTIME_POOL, subclass_name);
-
+
switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass);
-
+
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool)
{
- switch_thread *thread;
- switch_threadattr_t *thd_attr;;
- switch_threadattr_create(&thd_attr, pool);
- switch_threadattr_detach_set(thd_attr, 1);
+ switch_thread *thread;
+ switch_threadattr_t *thd_attr;;
+ switch_threadattr_create(&thd_attr, pool);
+ switch_threadattr_detach_set(thd_attr, 1);
assert(pool != NULL);
RUNTIME_POOL = pool;
if (switch_core_new_memory_pool(&APOOL) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
- return SWITCH_STATUS_MEMERR;
- }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
+ return SWITCH_STATUS_MEMERR;
+ }
if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
- return SWITCH_STATUS_MEMERR;
- }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
+ return SWITCH_STATUS_MEMERR;
+ }
THRUNTIME_POOL = APOOL;
switch_queue_create(&EVENT_QUEUE, POOL_COUNT_MAX + 10, THRUNTIME_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) {
switch_yield(1000);
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...)
{
- int ret = 0;
+ int ret = 0;
char data[2048];
- va_list ap;
+ va_list ap;
va_start(ap, fmt);
vsnprintf(data, sizeof(data), fmt, ap);
va_end(ap);
return SWITCH_STATUS_MEMERR;
} else {
switch_event_header *header, *hp;
-
+
if (!(header = ALLOC(sizeof(*header)))) {
return SWITCH_STATUS_MEMERR;
}
event->headers = header;
} else {
for (hp = event->headers; hp && hp->next; hp = hp->next);
-
+
if (hp) {
hp->next = header;
} else {
return SWITCH_STATUS_SUCCESS;
}
-
+
return (ret >= 0) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;
-
+
}
SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *fmt, ...)
{
- int ret = 0;
+ int ret = 0;
char data[2048];
- va_list ap;
+ va_list ap;
va_start(ap, fmt);
vsnprintf(data, sizeof(data), fmt, ap);
va_end(ap);
event->body = DUP(data);
return SWITCH_STATUS_SUCCESS;
}
-
+
return (ret >= 0) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;
-
+
}
SWITCH_DECLARE(void) switch_event_destroy(switch_event **event)
if (switch_event_create_subclass(event, todup->event_id, todup->subclass->name) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
-
+
(*event)->subclass = todup->subclass;
(*event)->event_user_data = todup->event_user_data;
(*event)->bind_user_data = todup->bind_user_data;
-
+
for (hp = todup->headers; hp && hp->next;) {
if (!(header = ALLOC(sizeof(*header)))) {
return SWITCH_STATUS_MEMERR;
{
size_t len = 0;
switch_event_header *hp;
- char *data = NULL, *body = NULL;
- int ret = 0;
- va_list ap;
+ char *data = NULL, *body = NULL;
+ int ret = 0;
+ va_list ap;
if (fmt) {
va_start(ap, fmt);
for (hp = event->headers; hp; hp = hp->next) {
snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value);
len = strlen(buf);
-
+
}
if (data) {
if (data) {
free(data);
}
-
+
return SWITCH_STATUS_SUCCESS;
}
assert(BLOCK != NULL);
assert(RUNTIME_POOL != NULL);
-
+
if (THREAD_RUNNING <= 0) {
/* sorry we're closed */
switch_event_destroy(event);
if (user_data) {
(*event)->event_user_data = user_data;
}
-
+
switch_queue_push(EVENT_QUEUE, *event);
*event = NULL;
if (!(ptr = (char *) fname)) {
continue;
}
-
+
if (!strstr(fname, ext) && !strstr(fname, EXT)) {
continue;
}
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);
+ (char *) ptr->interface_name,
+ (void *) ptr);
}
}
-
+
if (new_module->interface->codec_interface) {
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) {
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);
+ (char *) ptr->iananame,
+ (void *) ptr);
}
}
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);
+ (char *) ptr->interface_name,
+ (void *) ptr);
}
}
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);
+ (char *) ptr->interface_name,
+ (void *) ptr);
}
}
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);
}
}
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);
+ (char *) ptr->interface_name,
+ (void *) ptr);
}
}
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);
+ (char *) ptr->extens[i],
+ (void *) ptr);
}
}
}
#include <switch_mutex.h>
SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock,
- switch_lock_flag flags,
- switch_memory_pool *pool)
+ switch_lock_flag flags,
+ switch_memory_pool *pool)
{
return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;
switch_memory_pool *pool)
{
switch_audio_resampler *resampler;
-
+
if (!(resampler = switch_core_alloc(pool, sizeof(*resampler)))) {
return SWITCH_STATUS_MEMERR;
}
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);
- //printf("resampling %d/%d (%d) %d %f\n", srcpos, srclen, MIN(dstlen-out, dstlen), srcused, factor);
+ 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;
if (o >= 0) {
- out += o;
+ out += o;
}
if (o < 0 || (o == 0 && srcpos == srclen)) {
- break;
+ break;
}
- }
- return out;
+ }
+ return out;
}
SWITCH_DECLARE(void) switch_resample_destroy(switch_audio_resampler *resampler)
switch_pollset_t *pollset;
switch_status status;
-
if ((status = switch_pollset_create(&pollset, 1, pool, flags)) != SWITCH_STATUS_SUCCESS) {
return status;
}
-
poll->desc_type = SWITCH_POLL_SOCKET;
poll->reqevents = flags;
poll->desc.s = sock;
poll->client_data = sock;
return switch_pollset_add(pollset, poll);
-
-
-
}
{
switch_status status;
int nsds = 0;
-
+
if ((status = switch_poll(poll, 1, &nsds, ms)) != SWITCH_STATUS_SUCCESS) {
return -1;
}
-
- return nsds;
-}
-
-#ifdef HAVE_TIMEVAL_STRUCT
-#define ONE_MILLION 1000000
-/*
- * put timeval in a valid range. usec is 0..999999
- * negative values are not allowed and truncated.
- */
-static struct timeval tvfix(struct timeval a)
-{
- if (a.tv_usec >= ONE_MILLION) {
- a.tv_sec += a.tv_usec % ONE_MILLION;
- a.tv_usec %= ONE_MILLION;
- } else if (a.tv_usec < 0) {
- a.tv_usec = 0;
- }
- return a;
-}
-
-struct timeval switch_tvadd(struct timeval a, struct timeval b)
-{
- /* consistency checks to guarantee usec in 0..999999 */
- a = tvfix(a);
- b = tvfix(b);
- a.tv_sec += b.tv_sec;
- a.tv_usec += b.tv_usec;
- if (a.tv_usec >= ONE_MILLION) {
- a.tv_sec++;
- a.tv_usec -= ONE_MILLION;
- }
- return a;
-}
-
-struct timeval switch_tvsub(struct timeval a, struct timeval b)
-{
- /* consistency checks to guarantee usec in 0..999999 */
- a = tvfix(a);
- b = tvfix(b);
- a.tv_sec -= b.tv_sec;
- a.tv_usec -= b.tv_usec;
- if (a.tv_usec < 0) {
- a.tv_sec-- ;
- a.tv_usec += ONE_MILLION;
- }
- return a;
+ return nsds;
}
-#undef ONE_MILLION
-#endif
#ifdef WIN32
//this forces certain symbols to not be optimized out of the dll