git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10533 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-11-25 17:53:35 +00:00
parent 50e1a8c23f
commit 1eea29a474
7 changed files with 68 additions and 37 deletions

View File

@ -351,6 +351,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_sessi
*/ */
SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags); SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, switch_io_flag_t io_flags);
SWITCH_DECLARE(void) rtp_flush_read_buffer(switch_rtp_t *rtp_session);
/*! /*!
\brief Enable VAD on an RTP Session \brief Enable VAD on an RTP Session
\param rtp_session the RTP session \param rtp_session the RTP session

View File

@ -568,6 +568,7 @@ typedef enum {
SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ, SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ,
SWITCH_MESSAGE_INDICATE_DISPLAY, SWITCH_MESSAGE_INDICATE_DISPLAY,
SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY, SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY,
SWITCH_MESSAGE_INDICATE_AUDIO_SYNC,
SWITCH_MESSAGE_INVALID SWITCH_MESSAGE_INVALID
} switch_core_session_message_types_t; } switch_core_session_message_types_t;
@ -742,7 +743,7 @@ CF_CONTROLLED = (1 << 12) - Channel is under control
CF_PROXY_MODE = (1 << 13) - Channel has no media CF_PROXY_MODE = (1 << 13) - Channel has no media
CF_SUSPEND = (1 << 14) - Suspend i/o CF_SUSPEND = (1 << 14) - Suspend i/o
CF_EVENT_PARSE = (1 << 15) - Suspend control events CF_EVENT_PARSE = (1 << 15) - Suspend control events
CF_REPEAT_STATE = (1 << 16) - Tell the state machine to repeat a state CF_USE_ME = (1 << 16) - use me
CF_GEN_RINGBACK = (1 << 17) - Channel is generating it's own ringback CF_GEN_RINGBACK = (1 << 17) - Channel is generating it's own ringback
CF_RING_READY = (1 << 18) - Channel is ready to send ringback CF_RING_READY = (1 << 18) - Channel is ready to send ringback
CF_BREAK = (1 << 19) - Channel should stop what it's doing CF_BREAK = (1 << 19) - Channel should stop what it's doing
@ -773,7 +774,7 @@ typedef enum {
CF_PROXY_MODE = (1 << 13), CF_PROXY_MODE = (1 << 13),
CF_SUSPEND = (1 << 14), CF_SUSPEND = (1 << 14),
CF_EVENT_PARSE = (1 << 15), CF_EVENT_PARSE = (1 << 15),
CF_REPEAT_STATE = (1 << 16), CF_USE_ME = (1 << 16),
CF_GEN_RINGBACK = (1 << 17), CF_GEN_RINGBACK = (1 << 17),
CF_RING_READY = (1 << 18), CF_RING_READY = (1 << 18),
CF_BREAK = (1 << 19), CF_BREAK = (1 << 19),

View File

@ -1127,8 +1127,8 @@ SWITCH_STANDARD_API(transfer_function)
} else if (!strcasecmp(arg, "both")) { } else if (!strcasecmp(arg, "both")) {
if (uuid && (other_session = switch_core_session_locate(uuid))) { if (uuid && (other_session = switch_core_session_locate(uuid))) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session); switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
switch_channel_set_flag(other_channel, CF_TRANSFER); switch_channel_set_flag(other_channel, CF_REDIRECT);
switch_channel_set_flag(channel, CF_TRANSFER); switch_channel_set_flag(channel, CF_REDIRECT);
switch_ivr_session_transfer(other_session, dest, dp, context); switch_ivr_session_transfer(other_session, dest, dp, context);
switch_core_session_rwunlock(other_session); switch_core_session_rwunlock(other_session);
} }

View File

@ -936,21 +936,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
goto end; goto end;
case SWITCH_MESSAGE_INDICATE_BRIDGE: case SWITCH_MESSAGE_INDICATE_BRIDGE:
/*
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
}
*/
goto end;
case SWITCH_MESSAGE_INDICATE_UNBRIDGE: case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
/* case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) { if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER); rtp_flush_read_buffer(tech_pvt->rtp_session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
} }
*/
goto end; goto end;
case SWITCH_MESSAGE_INDICATE_ANSWER: case SWITCH_MESSAGE_INDICATE_ANSWER:

View File

@ -360,19 +360,15 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
switch_mutex_lock(session->mutex); switch_mutex_lock(session->mutex);
while ((state = switch_channel_get_state(session->channel)) != CS_DONE) { while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
uint8_t exception = 0;
midstate = state; midstate = state;
if (switch_channel_test_flag(session->channel, CF_REPEAT_STATE)) { if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP) {
switch_channel_clear_flag(session->channel, CF_REPEAT_STATE);
exception = 1;
}
if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP || exception) {
int index = 0; int index = 0;
int proceed = 1; int proceed = 1;
int do_extra_handlers = 1; int do_extra_handlers = 1;
switch_channel_set_running_state(session->channel, state); switch_channel_set_running_state(session->channel, state);
switch_channel_clear_flag(session->channel, CF_TRANSFER); switch_channel_clear_flag(session->channel, CF_TRANSFER);
switch_channel_clear_flag(session->channel, CF_REDIRECT);
switch (state) { switch (state) {
case CS_NEW: /* Just created, Waiting for first instructions */ case CS_NEW: /* Just created, Waiting for first instructions */

View File

@ -209,11 +209,11 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
goto end_of_bridge_loop; goto end_of_bridge_loop;
} }
if (switch_channel_test_flag(chan_a, CF_TRANSFER) || switch_channel_test_flag(chan_a, CF_REDIRECT)) { if (switch_channel_test_flag(chan_a, CF_TRANSFER)) {
data->clean_exit = 1; data->clean_exit = 1;
} }
if (data->clean_exit || switch_channel_test_flag(chan_b, CF_TRANSFER) || switch_channel_test_flag(chan_b, CF_REDIRECT)) { if (data->clean_exit || switch_channel_test_flag(chan_b, CF_TRANSFER)) {
switch_channel_clear_flag(chan_a, CF_HOLD); switch_channel_clear_flag(chan_a, CF_HOLD);
switch_channel_clear_flag(chan_a, CF_SUSPEND); switch_channel_clear_flag(chan_a, CF_SUSPEND);
goto end_of_bridge_loop; goto end_of_bridge_loop;
@ -465,12 +465,13 @@ static switch_status_t audio_bridge_on_exchange_media(switch_core_session_t *ses
if (state < CS_HANGUP && switch_true(switch_channel_get_variable(channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) { if (state < CS_HANGUP && switch_true(switch_channel_get_variable(channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
switch_ivr_park_session(session); switch_ivr_park_session(session);
} else { } else {
if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) && bd && !bd->clean_exit && state != CS_PARK && if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) && bd && !bd->clean_exit
state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) { && state != CS_PARK && state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
} }
} }
if (switch_true(switch_channel_get_variable(channel, SWITCH_COPY_XML_CDR_VARIABLE))) { if (switch_true(switch_channel_get_variable(channel, SWITCH_COPY_XML_CDR_VARIABLE))) {
switch_xml_t cdr; switch_xml_t cdr;
char *xml_text; char *xml_text;
@ -528,8 +529,6 @@ static switch_status_t uuid_bridge_on_reset(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM RESET\n", switch_channel_get_name(channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CUSTOM RESET\n", switch_channel_get_name(channel));
switch_channel_clear_flag(channel, CF_REDIRECT);
switch_channel_clear_flag(channel, CF_ORIGINATING); switch_channel_clear_flag(channel, CF_ORIGINATING);
if (switch_channel_test_flag(channel, CF_ORIGINATOR)) { if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
@ -623,7 +622,9 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
switch_ivr_multi_threaded_bridge(session, other_session, NULL, NULL, NULL); switch_ivr_multi_threaded_bridge(session, other_session, NULL, NULL, NULL);
state = switch_channel_get_state(channel); state = switch_channel_get_state(channel);
if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) && state < CS_HANGUP && state != CS_ROUTING && state != CS_PARK) { if (!switch_channel_test_flag(channel, CF_TRANSFER) &&
!switch_channel_test_flag(channel, CF_REDIRECT) && state < CS_HANGUP
&& state != CS_ROUTING && state != CS_PARK) {
switch_channel_set_state(channel, CS_EXECUTE); switch_channel_set_state(channel, CS_EXECUTE);
} }
switch_core_session_rwunlock(other_session); switch_core_session_rwunlock(other_session);
@ -956,9 +957,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
} }
if (switch_channel_test_flag(caller_channel, CF_REDIRECT)) { if (switch_channel_test_flag(caller_channel, CF_REDIRECT)) {
state = switch_channel_get_state(caller_channel);
if (!(state == CS_RESET || state == CS_PARK || state == CS_ROUTING)) {
switch_channel_set_state(caller_channel, CS_RESET); switch_channel_set_state(caller_channel, CS_RESET);
} }
}
return status; return status;
} }

View File

@ -1263,6 +1263,40 @@ static void do_2833(switch_rtp_t *rtp_session)
} }
} }
SWITCH_DECLARE(void) rtp_flush_read_buffer(switch_rtp_t *rtp_session)
{
int was_blocking = 0;
switch_size_t bytes;
switch_status_t status;
if (!switch_rtp_ready(rtp_session)) {
return;
}
READ_INC(rtp_session);
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
was_blocking = 1;
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, TRUE);
}
do {
bytes = sizeof(rtp_msg_t);
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, &bytes);
} while(bytes);
if (was_blocking) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE);
}
READ_DEC(rtp_session);
}
#define return_cng_frame() do_cng = 1; goto timer_check #define return_cng_frame() do_cng = 1; goto timer_check
static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags) static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
@ -1315,6 +1349,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
do_2833(rtp_session); do_2833(rtp_session);
rtp_flush_read_buffer(rtp_session);
bytes = 0; bytes = 0;
return_cng_frame(); return_cng_frame();
} }
@ -1323,6 +1358,10 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
continue; continue;
} }
if (bytes && rtp_session->recv_msg.header.m) {
rtp_flush_read_buffer(rtp_session);
}
if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) { if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
if (++rtp_session->autoadj_tally >= 10) { if (++rtp_session->autoadj_tally >= 10) {
const char *tx_host; const char *tx_host;