From b91edd017c4d12660ad7b01a840647a7d8cc5fb1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 17 Nov 2005 16:21:58 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/local/src/freeswitch@21 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- Makefile.am | 2 +- Makefile.in | 2 +- src/mod/mod_exosip/mod_exosip.c | 46 ++++++++++++++++----------------- src/switch_core.c | 46 ++++++++++++++++++++++----------- 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/Makefile.am b/Makefile.am index daf43fb0ee..362f0d5d03 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ APR_CONFIG=$(prefix)/bin/apr-1-config AM_CFLAGS = $(shell $(APR_CONFIG) --cflags --cppflags --includes) AM_LDFLAGS = $(shell $(APR_CONFIG) --link-ld --libs ) -Wl,-E -L$(PREFIX)/lib AM_CFLAGS += -fPIC -Wall -AM_CFLAGS +=-I$(PWD) -I$(PWD)/include -I$(PREFIX)/include +AM_CFLAGS +=-I$(PWD) -I$(PWD)/src/include -I$(PREFIX)/include AM_CFLAGS += -DSWITCH_MOD_DIR=\"$(PREFIX)/mod\" AM_CFLAGS += -DSWITCH_PREFIX_DIR=\"$(PREFIX)\" AM_CFLAGS += -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" diff --git a/Makefile.in b/Makefile.in index 38cc8b85be..e8382773a1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -136,7 +136,7 @@ MAKE = gmake NAME = freeswitch PREFIX = $(prefix)/${NAME} APR_CONFIG = $(prefix)/bin/apr-1-config -AM_CFLAGS = $(shell $(APR_CONFIG) --cflags --cppflags --includes) -fPIC -Wall -I$(PWD) -I$(PWD)/include -I$(PREFIX)/include -DSWITCH_MOD_DIR=\"$(PREFIX)/mod\" -DSWITCH_PREFIX_DIR=\"$(PREFIX)\" -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" +AM_CFLAGS = $(shell $(APR_CONFIG) --cflags --cppflags --includes) -fPIC -Wall -I$(PWD) -I$(PWD)/src/include -I$(PREFIX)/include -DSWITCH_MOD_DIR=\"$(PREFIX)/mod\" -DSWITCH_PREFIX_DIR=\"$(PREFIX)\" -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" AM_LDFLAGS = $(shell $(APR_CONFIG) --link-ld --libs ) -Wl,-E -L$(PREFIX)/lib libfreeswitch_la_SOURCES = \ diff --git a/src/mod/mod_exosip/mod_exosip.c b/src/mod/mod_exosip/mod_exosip.c index ac3526d24b..00c67b2e9c 100644 --- a/src/mod/mod_exosip/mod_exosip.c +++ b/src/mod/mod_exosip/mod_exosip.c @@ -471,12 +471,14 @@ static void activate_rtp(struct private_object *tech_pvt) tech_pvt->remote_sdp_audio_port, tech_pvt->read_codec.codec_interface->ianacode, ms, - ms * 15); + ms * 15, + (ms / 1000) * 2); if (tech_pvt->rtp_session) { tech_pvt->ssrc = ccrtp4c_get_ssrc(tech_pvt->rtp_session); + //tech_pvt->timestamp_recv = tech_pvt->timestamp_send = ccrtp4c_start(tech_pvt->rtp_session); - tech_pvt->timestamp_recv = tech_pvt->timestamp_send = ccrtp4c_current_timestamp(tech_pvt->rtp_session); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Initial Timestamp %u\n", tech_pvt->timestamp_recv); switch_set_flag(tech_pvt, TFLAG_RTP); } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Oh oh?\n"); @@ -522,8 +524,6 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram struct private_object *tech_pvt = NULL; size_t bytes = 0, samples = 0, frames=0, ms=0; switch_channel *channel = NULL; - switch_time_t reference, now; - int mult = 1; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -550,35 +550,34 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram assert(tech_pvt->rtp_session != NULL); tech_pvt->read_frame.datalen = 0; - reference = switch_time_now(); - reference += (ms * mult); while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) { - if ((tech_pvt->read_frame.datalen = - ccrtp4c_read(tech_pvt->rtp_session, - tech_pvt->read_frame.data, - sizeof(tech_pvt->read_buf), - &tech_pvt->timestamp_recv))) { + int offset; + + tech_pvt->read_frame.datalen = ccrtp4c_read(tech_pvt->rtp_session, + tech_pvt->read_frame.data, + sizeof(tech_pvt->read_buf), + tech_pvt->timestamp_recv, + &offset); + + 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 += samples; break; + } else if (offset) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Timestamp behind by %d samples... auto-correcting\n", offset); + tech_pvt->timestamp_recv += offset; + continue; } - now = switch_time_now(); - if (now >= reference) { - //printf("TO\n"); - memset(tech_pvt->read_buf, 0, bytes * mult); - tech_pvt->timestamp_recv += (samples * mult); - reference += (ms * mult); - tech_pvt->read_frame.datalen = bytes *2; - break; - } - switch_yield(100); } - + + //tech_pvt->timestamp_recv += samples; + + //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); @@ -646,7 +645,7 @@ 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); - ccrtp4c_write(tech_pvt->rtp_session, frame->data, frame->datalen, &tech_pvt->timestamp_send); + ccrtp4c_write(tech_pvt->rtp_session, frame->data, frame->datalen, tech_pvt->timestamp_send); tech_pvt->timestamp_send += (int)samples; switch_clear_flag(tech_pvt, TFLAG_WRITING); @@ -1084,7 +1083,6 @@ static void handle_answer(eXosip_event_t *event) assert(channel != NULL); switch_channel_answer(channel); - } static void log_event(eXosip_event_t *je) diff --git a/src/switch_core.c b/src/switch_core.c index 585fef5c1f..2de1705c3b 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1087,7 +1087,7 @@ SWITCH_DECLARE(void) pbx_core_session_signal_state_change(switch_core_session *s SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) { - switch_channel_state state = CS_NEW, laststate = CS_HANGUP; + switch_channel_state state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE; const switch_endpoint_interface *endpoint_interface; const switch_event_handler_table *driver_event_handlers = NULL; const switch_event_handler_table *application_event_handlers = NULL; @@ -1120,6 +1120,9 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) while ((state = switch_channel_get_state(session->channel)) != CS_DONE) { if (state != laststate) { + + midstate = state; + switch ( state ) { case CS_NEW: /* Just created, Waiting for first instructions */ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n"); @@ -1131,10 +1134,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) 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)) { + 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)) { + application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_hangup(session); } } @@ -1144,10 +1149,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) 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)) { + 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)) { + application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_init(session); } } @@ -1156,10 +1163,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) 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)) { + 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)) { + application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_ring(session); } } @@ -1168,10 +1177,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) 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)) { + 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)) { + application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_execute(session); } } @@ -1180,10 +1191,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) 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)) { + 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)) { + application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_loopback(session); } } @@ -1192,19 +1205,22 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) 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)) { + 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)) { + application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { switch_core_standard_on_transmit(session); } } break; } - laststate = state; + + laststate = midstate; } - if (state < CS_DONE) { + if (state < CS_DONE && midstate == switch_channel_get_state(session->channel)) { switch_thread_cond_wait(session->cond, session->mutex); } }