git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@418 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2006-01-20 02:02:03 +00:00
parent 1e04eb13b5
commit 0ea203849f
43 changed files with 3940 additions and 4103 deletions

View File

@@ -61,7 +61,7 @@ typedef enum {
TFLAG_DTMF = (1 << 3),
TFLAG_READING = (1 << 4),
TFLAG_WRITING = (1 << 5),
TFLAG_USING_CODEC = (1 << 6),
TFLAG_USING_CODEC = (1 << 6),
TFLAG_RTP = (1 << 7),
TFLAG_BYE = (1 << 8)
} TFLAGS;
@@ -87,7 +87,7 @@ static struct {
} globals;
struct private_object {
unsigned int flags;
unsigned int flags;
switch_core_session *session;
switch_frame read_frame;
switch_codec read_codec;
@@ -144,14 +144,11 @@ static switch_status exosip_on_init(switch_core_session *session);
static switch_status exosip_on_hangup(switch_core_session *session);
static switch_status exosip_on_loopback(switch_core_session *session);
static switch_status exosip_on_transmit(switch_core_session *session);
static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
switch_core_session **new_session);
static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
switch_io_flag flags, int stream_id);
static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
switch_io_flag flags, int stream_id);
static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
static int config_exosip(int reload);
static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload);
static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload);
static switch_status exosip_kill_channel(switch_core_session *session, int sig);
static void activate_rtp(struct private_object *tech_pvt);
static void deactivate_rtp(struct private_object *tech_pvt);
@@ -193,16 +190,16 @@ static int sdp_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload,
}
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;
}
@@ -235,7 +232,7 @@ static switch_status exosip_on_init(switch_core_session *session)
char *dest_uri;
switch_codec_interface *codecs[SWITCH_MAX_CODECS];
int num_codecs = 0;
/* do SIP Goodies... */
/* do SIP Goodies...*/
/* Generate callerid URI */
eXosip_guess_localip(AF_INET, localip, 128);
@@ -248,17 +245,14 @@ static switch_status exosip_on_init(switch_core_session *session)
/* Initialize SDP */
sdp_message_init(&tech_pvt->local_sdp);
sdp_message_v_version_set(tech_pvt->local_sdp, "0");
sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
tech_pvt->local_sdp_audio_ip);
sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0");
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP");
/* Add in every codec we support on this outbound call */
if ((num_codecs =
switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
sizeof(codecs) / sizeof(codecs[0]))) > 0) {
if ((num_codecs = switch_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;
for (i = 0; i < num_codecs; i++) {
@@ -266,14 +260,12 @@ static switch_status exosip_on_init(switch_core_session *session)
snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode);
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
for (imp = codecs[i]->implementations; imp; imp = imp->next) {
for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
/* Add to SDP config */
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
imp->samples_per_second, x++);
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
/* Add to SDP message */
snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame,
imp->samples_per_second);
snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second);
sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp));
memset(tmp, 0, sizeof(tmp));
}
@@ -281,9 +273,7 @@ static switch_status exosip_on_init(switch_core_session *session)
}
/* Setup our INVITE */
eXosip_lock();
if (!
(dest_uri =
(char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n");
assert(dest_uri != NULL);
}
@@ -302,7 +292,7 @@ static switch_status exosip_on_init(switch_core_session *session)
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
tech_pvt->did = -1;
eXosip_unlock();
}
}
/* Let Media Work */
switch_set_flag(tech_pvt, TFLAG_IO);
@@ -341,7 +331,7 @@ static switch_status exosip_on_hangup(switch_core_session *session)
assert(tech_pvt != NULL);
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
switch_set_flag(tech_pvt, TFLAG_BYE);
@@ -356,8 +346,7 @@ static switch_status exosip_on_hangup(switch_core_session *session)
switch_core_codec_destroy(&tech_pvt->write_codec);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel),
tech_pvt->cid, tech_pvt->did, i);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i);
return SWITCH_STATUS_SUCCESS;
}
@@ -373,16 +362,14 @@ static switch_status exosip_on_transmit(switch_core_session *session)
return SWITCH_STATUS_SUCCESS;
}
static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
switch_core_session **new_session)
static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_channel *channel;
switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
@@ -425,7 +412,7 @@ static void deactivate_rtp(struct private_object *tech_pvt)
if (tech_pvt->rtp_session) {
switch_mutex_lock(tech_pvt->rtp_lock);
while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
switch_yield(10000);
loops++;
}
@@ -467,20 +454,25 @@ static void activate_rtp(struct private_object *tech_pvt)
}
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->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);
if (tech_pvt->rtp_session) {
tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session);
@@ -519,21 +511,20 @@ static switch_status exosip_answer_channel(switch_core_session *session)
sdp_message_to_str(tech_pvt->local_sdp, &buf);
osip_message_set_body(answer, buf, strlen(buf));
osip_message_set_content_type(answer, "application/sdp");
free(buf);
free(buf);
eXosip_call_send_answer(tech_pvt->tid, 200, answer);
eXosip_unlock();
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
switch_io_flag flags, int stream_id)
static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
{
struct private_object *tech_pvt = NULL;
size_t bytes = 0, samples = 0, frames = 0, ms = 0;
size_t bytes = 0, samples = 0, frames=0, ms=0;
switch_channel *channel = NULL;
channel = switch_core_session_get_channel(session);
@@ -562,18 +553,18 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
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));
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));
if (tech_pvt->read_frame.datalen > 0) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
tech_pvt->timestamp_recv += (int32_t) samples;
tech_pvt->read_frame.samples = (int) samples;
tech_pvt->timestamp_recv += (int32_t)samples;
tech_pvt->read_frame.samples = (int)samples;
break;
}
@@ -607,13 +598,12 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
}
static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
switch_io_flag flags, int stream_id)
static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
switch_status status = SWITCH_STATUS_SUCCESS;
int bytes = 0, samples = 0, ms = 0, frames = 0;
int bytes=0, samples=0, ms=0, frames=0;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -639,7 +629,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
if (switch_test_flag(tech_pvt, TFLAG_USING_CODEC)) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = ((int) frame->datalen / bytes);
frames = ((int)frame->datalen / bytes);
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame / 1000;
} else {
@@ -650,8 +640,8 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
//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);
jrtp4c_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
tech_pvt->timestamp_send += (int) samples;
jrtp4c_write(tech_pvt->rtp_session, frame->data, (int)frame->datalen, samples);
tech_pvt->timestamp_send += (int)samples;
switch_clear_flag(tech_pvt, TFLAG_WRITING);
//switch_mutex_unlock(tech_pvt->rtp_lock);
@@ -710,39 +700,39 @@ static switch_status exosip_waitfor_write(switch_core_session *session, int ms,
}
static const switch_io_routines exosip_io_routines = {
/*.outgoing_channel */ exosip_outgoing_channel,
/*.answer_channel */ exosip_answer_channel,
/*.read_frame */ exosip_read_frame,
/*.write_frame */ exosip_write_frame,
/*.kill_channel */ exosip_kill_channel,
/*.waitfor_read */ exosip_waitfor_read,
/*.waitfor_read */ exosip_waitfor_write
/*.outgoing_channel*/ exosip_outgoing_channel,
/*.answer_channel*/ exosip_answer_channel,
/*.read_frame*/ exosip_read_frame,
/*.write_frame*/ exosip_write_frame,
/*.kill_channel*/ exosip_kill_channel,
/*.waitfor_read*/ exosip_waitfor_read,
/*.waitfor_read*/ exosip_waitfor_write
};
static const switch_event_handler_table exosip_event_handlers = {
/*.on_init */ exosip_on_init,
/*.on_ring */ exosip_on_ring,
/*.on_execute */ exosip_on_execute,
/*.on_hangup */ exosip_on_hangup,
/*.on_loopback */ exosip_on_loopback,
/*.on_transmit */ exosip_on_transmit
static const switch_event_handler_table exosip_event_handlers = {
/*.on_init*/ exosip_on_init,
/*.on_ring*/ exosip_on_ring,
/*.on_execute*/ exosip_on_execute,
/*.on_hangup*/ exosip_on_hangup,
/*.on_loopback*/ exosip_on_loopback,
/*.on_transmit*/ exosip_on_transmit
};
static const switch_endpoint_interface exosip_endpoint_interface = {
/*.interface_name */ "exosip",
/*.io_routines */ &exosip_io_routines,
/*.event_handlers */ &exosip_event_handlers,
/*.private */ NULL,
/*.next */ NULL
/*.interface_name*/ "exosip",
/*.io_routines*/ &exosip_io_routines,
/*.event_handlers*/ &exosip_event_handlers,
/*.private*/ NULL,
/*.next*/ NULL
};
static const switch_loadable_module_interface exosip_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ &exosip_endpoint_interface,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL
/*.module_name*/ modname,
/*.endpoint_interface*/ &exosip_endpoint_interface,
/*.timer_interface*/ NULL,
/*.dialplan_interface*/ NULL,
/*.codec_interface*/ NULL,
/*.application_interface*/ NULL
};
#if 1
@@ -750,15 +740,14 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
if (globals.running) {
globals.running = -1;
while (globals.running) {
while(globals.running) {
switch_yield(100000);
}
}
return SWITCH_STATUS_SUCCESS;
}
#endif
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
{
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
/* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
@@ -773,7 +762,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
return SWITCH_STATUS_SUCCESS;
}
static switch_status exosip_create_call(eXosip_event_t * event)
static switch_status exosip_create_call(eXosip_event_t *event)
{
switch_core_session *session;
sdp_message_t *remote_sdp = NULL;
@@ -805,12 +794,14 @@ static switch_status exosip_create_call(eXosip_event_t * event)
}
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);
@@ -833,17 +824,14 @@ static switch_status exosip_create_call(eXosip_event_t * event)
osip_rfc3264_init(&tech_pvt->sdp_config);
/* Add in what codecs we support locally */
if ((num_codecs =
switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
sizeof(codecs) / sizeof(codecs[0]))) > 0) {
if ((num_codecs = switch_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;
for (i = 0; i < num_codecs; i++) {
int x = 0;
for (imp = codecs[i]->implementations; imp; imp = imp->next) {
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
imp->samples_per_second, x++);
for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
}
}
}
@@ -852,18 +840,17 @@ static switch_status exosip_create_call(eXosip_event_t * event)
sdp_message_parse(tech_pvt->local_sdp, local_sdp_str);
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);
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)) {
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) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n");
break;
}
for (pos = 0; audio_tab[pos] != NULL; pos++) {
osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos],
mline);
for (pos=0; audio_tab[pos]!=NULL; pos++) {
osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline);
if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) {
tech_pvt->payload_num = atoi(dpayload);
break;
@@ -872,8 +859,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
mline++;
}
free(remote_sdp_str);
sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
tech_pvt->local_sdp_audio_ip);
sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
@@ -886,7 +872,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
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);
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
if (!dname) {
exosip_on_hangup(session);
@@ -901,33 +887,34 @@ static switch_status exosip_create_call(eXosip_event_t * event)
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;
switch_set_flag(tech_pvt, TFLAG_USING_CODEC);
ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate,
ms);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
@@ -952,14 +939,13 @@ static switch_status exosip_create_call(eXosip_event_t * event)
}
static void destroy_call_by_event(eXosip_event_t * event)
static void destroy_call_by_event(eXosip_event_t *event)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
if (!(tech_pvt = get_pvt_by_call_id(event->cid))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n",
event->cid);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid);
return;
}
@@ -972,7 +958,7 @@ static void destroy_call_by_event(eXosip_event_t * event)
}
static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload)
static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload)
{
int pos = 0;
sdp_attribute_t *attr = NULL;
@@ -980,7 +966,7 @@ static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **d
switch_status status = SWITCH_STATUS_GENERR;
while (osip_list_eol(media->a_attributes, pos) == 0) {
attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos);
attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos);
if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) {
payload = attr->a_att_value;
if ((name = strchr(payload, ' '))) {
@@ -1001,8 +987,7 @@ static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **d
*dname = strdup("L16");
*drate = strdup("8000");
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n",
*dpayload, *dname, *drate);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate);
break;
}
attr = NULL;
@@ -1012,7 +997,7 @@ static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **d
return status;
}
static void handle_answer(eXosip_event_t * event)
static void handle_answer(eXosip_event_t *event)
{
osip_message_t *ack = NULL;
sdp_message_t *remote_sdp = NULL;
@@ -1067,27 +1052,28 @@ static void handle_answer(eXosip_event_t * event)
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;
@@ -1121,119 +1107,133 @@ static void handle_answer(eXosip_event_t * event)
}
}
static void log_event(eXosip_event_t * je)
static void log_event(eXosip_event_t *je)
{
char buf[100];
buf[0] = '\0';
if (je->type == EXOSIP_CALL_NOANSWER) {
snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did);
snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_CLOSED) {
snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
} 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;
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);
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_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);
osip_free(tmp);
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) %s from: %s",
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;
|| 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);
}
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);
osip_free(tmp);
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);
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);
osip_free(tmp);
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);
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);
osip_free(tmp);
osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) %s from: %s",
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);
osip_free(tmp);
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);
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);
osip_message_header_get_byname (je->request, "subscription-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);
osip_free(tmp);
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);
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);
osip_free(tmp);
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);
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);
osip_free(tmp);
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);
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);
osip_free(tmp);
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);
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);
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);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf);
/* Print it out */
@@ -1241,7 +1241,7 @@ static void log_event(eXosip_event_t * je)
static int config_exosip(int reload)
static int config_exosip(int reload)
{
switch_config cfg;
char *var, *val;
@@ -1307,88 +1307,88 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
config_exosip(0);
if (eXosip_init()) {
if (eXosip_init ()) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n");
return SWITCH_STATUS_TERM;
}
if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n");
return SWITCH_STATUS_TERM;
}
globals.running = 1;
while (globals.running > 0) {
if (!(event = eXosip_event_wait(0, 100))) {
if (!(event = eXosip_event_wait(0,100))) {
switch_yield(1000);
continue;
}
eXosip_lock();
eXosip_automatic_action();
eXosip_automatic_action ();
eXosip_unlock();
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;
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;
}
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo);
@@ -1399,7 +1399,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
eXosip_quit();
globals.running = 0;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Monitor Thread Exiting\n");
//switch_sleep(2000000);
//switch_sleep(2000000);
return SWITCH_STATUS_TERM;
}