提交 ed41805c authored 作者: Anthony Minessale's avatar Anthony Minessale

improve core and basic flow

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4174 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 e6dac092
......@@ -294,6 +294,13 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
*/
#define switch_channel_mark_answered(channel) switch_channel_perform_mark_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
/*!
\brief Mark a channel pre_answered (early media) with no indication (for outbound calls)
\param channel channel to mark pre_answered
\return SWITCH_STATUS_SUCCESS if channel was pre_answered successfully
*/
#define switch_channel_mark_pre_answered(channel) switch_channel_perform_mark_pre_answered(channel, __FILE__, __SWITCH_FUNC__, __LINE__)
SWITCH_DECLARE(switch_status_t) switch_channel_perform_ringback(switch_channel_t *channel,
const char *file,
const char *func,
......@@ -310,6 +317,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel
const char *file,
const char *func,
int line);
SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_channel_t *channel,
const char *file,
const char *func,
int line);
/*!
\brief Indicate progress on a channel to attempt early media
\param channel channel to pre-answer
......
......@@ -522,6 +522,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_queue_message(switch_core_se
*/
SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_message(switch_core_session_t *session, switch_core_session_message_t **message);
/*!
\brief Flush a message queue on a given session
\param session the session to de-queue the message on
\return the SWITCH_STATUS_SUCCESS if the message was de-queued
*/
SWITCH_DECLARE(switch_status_t) switch_core_session_flush_message(switch_core_session_t *session);
/*!
\brief Queue an event on another session using its uuid
\param uuid_str the unique id of the session you want to send a message to
......
......@@ -1035,7 +1035,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
case IAX_EVENT_ACCEPT:
if (channel && !switch_channel_test_flag(channel, CF_ANSWERED)) {
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
switch_channel_mark_pre_answered(channel);
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
......
......@@ -1580,7 +1580,7 @@ static switch_status_t tech_media(private_object_t *tech_pvt, char *r_sdp)
activate_rtp(tech_pvt);
switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
switch_channel_mark_pre_answered(channel);
return SWITCH_STATUS_SUCCESS;
}
......@@ -2784,7 +2784,7 @@ static void sip_i_state(int status,
if (r_sdp) {
if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
switch_channel_mark_pre_answered(channel);
if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
other_channel = switch_core_session_get_channel(other_session);
switch_channel_pre_answer(other_channel);
......
......@@ -978,6 +978,38 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
return channel->state;
}
SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_channel_t *channel,
const char *file,
const char *func,
int line)
{
switch_event_t *event;
if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
char *uuid;
switch_core_session_t *other_session;
switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Pre-Answer %s!\n", channel->name);
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
/* if we're in a bridge and the other channel is in a blocking read they will never realize we have answered so send
a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
*/
if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
switch_core_session_rwunlock(other_session);
}
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel_t *channel,
const char *file,
const char *func,
......@@ -1006,15 +1038,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel
status = switch_core_session_message_send(uuid, &msg);
if (status == SWITCH_STATUS_SUCCESS) {
switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Pre-Answer %s!\n", channel->name);
switch_channel_set_flag(channel, CF_EARLY_MEDIA);
switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_PROGRESS) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
status = switch_channel_perform_mark_pre_answered(channel, file, func, line);
}
return status;
......@@ -1060,6 +1084,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
int line)
{
switch_event_t *event;
char *uuid;
switch_core_session_t *other_session;
assert(channel != NULL);
......@@ -1083,6 +1109,15 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
/* if we're in a bridge and the other channel is in a blocking read they will never realize we have answered so send
a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
*/
if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
switch_core_session_rwunlock(other_session);
}
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name);
......
......@@ -1766,6 +1766,22 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_message(switch_core_
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_flush_message(switch_core_session_t *session)
{
switch_core_session_message_t *message;
if (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
if (switch_test_flag(message, SCSMF_DYNAMIC)) {
switch_safe_free(message);
} else {
message = NULL;
}
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_receive_event(switch_core_session_t *session, switch_event_t **event)
{
......@@ -2151,6 +2167,9 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session)
session->read_resampler = NULL;
session->write_resampler = NULL;
/* clear indications */
switch_core_session_flush_message(session);
/* wipe theese, they will be recreated if need be */
switch_buffer_destroy(&session->raw_read_buffer);
switch_buffer_destroy(&session->raw_write_buffer);
......
......@@ -2021,8 +2021,9 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
message = NULL;
}
}
if (!ans_a && originator) {
if (!ans_b && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
switch_channel_answer(chan_a);
ans_a++;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论