Author: anthm Date: Tue Dec 5 18:08:14 2006 New Revision: 3549 Modified: freeswitch/trunk/src/include/switch_channel.h freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c freeswitch/trunk/src/switch_channel.c Log: answer tweak Modified: freeswitch/trunk/src/include/switch_channel.h ============================================================================== --- freeswitch/trunk/src/include/switch_channel.h (original) +++ freeswitch/trunk/src/include/switch_channel.h Tue Dec 5 18:08:14 2006 @@ -274,6 +274,12 @@ const char *file, const char *func, int line); + +SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel, + const char *file, + const char *func, + int line); + /*! \brief Answer a channel (initiate/acknowledge a successful connection) \param channel channel to answer @@ -281,6 +287,12 @@ */ #define switch_channel_answer(channel) switch_channel_perform_answer(channel, __FILE__, __FUNCTION__, __LINE__) +/*! + \brief Mark a channel answered with no indication (for outbound calls) + \param channel channel to mark answered + \return SWITCH_STATUS_SUCCESS if channel was answered successfully +*/ +#define switch_channel_mark_answered(channel) switch_channel_perform_mark_answered(channel, __FILE__, __FUNCTION__, __LINE__) SWITCH_DECLARE(switch_status_t) switch_channel_perform_ringback(switch_channel_t *channel, const char *file, Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Tue Dec 5 18:08:14 2006 @@ -2721,7 +2721,7 @@ if (r_sdp) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { switch_set_flag_locked(tech_pvt, TFLAG_ANS); - switch_channel_set_flag(channel, CF_ANSWERED); + switch_channel_mark_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_answer(other_channel); @@ -2749,7 +2749,7 @@ switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER"); tech_choose_port(tech_pvt); activate_rtp(tech_pvt); - switch_channel_set_flag(channel, CF_ANSWERED); + switch_channel_mark_answered(channel); return; } @@ -2759,7 +2759,7 @@ } else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) { switch_set_flag_locked(tech_pvt, TFLAG_ANS); switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER"); - switch_channel_set_flag(channel, CF_ANSWERED); + switch_channel_mark_answered(channel); return; } //else probably an ack } Modified: freeswitch/trunk/src/switch_channel.c ============================================================================== --- freeswitch/trunk/src/switch_channel.c (original) +++ freeswitch/trunk/src/switch_channel.c Tue Dec 5 18:08:14 2006 @@ -1049,6 +1049,41 @@ return status; } +SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel, + const char *file, + const char *func, + int line) +{ + switch_event_t *event; + + assert(channel != NULL); + + if (channel->state >= CS_HANGUP) { + return SWITCH_STATUS_FALSE; + } + + if (switch_channel_test_flag(channel, CF_ANSWERED)) { + return SWITCH_STATUS_SUCCESS; + } + + if (channel->caller_profile && channel->caller_profile->times) { + switch_mutex_lock(channel->profile_mutex); + channel->caller_profile->times->answered = switch_time_now(); + switch_mutex_unlock(channel->profile_mutex); + } + + switch_channel_set_flag(channel, CF_ANSWERED); + + if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(channel, event); + switch_event_fire(&event); + } + + switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name); + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel, const char *file, const char *func, @@ -1065,21 +1100,7 @@ } if (switch_core_session_answer_channel(channel->session) == SWITCH_STATUS_SUCCESS) { - switch_event_t *event; - - if (channel->caller_profile && channel->caller_profile->times) { - switch_mutex_lock(channel->profile_mutex); - channel->caller_profile->times->answered = switch_time_now(); - switch_mutex_unlock(channel->profile_mutex); - } - - switch_channel_set_flag(channel, CF_ANSWERED); - switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Answer %s!\n", channel->name); - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - return SWITCH_STATUS_SUCCESS; + return switch_channel_perform_mark_answered(channel, file, func, line); } return SWITCH_STATUS_FALSE;