From 361dc67be2265a48bce639fe045a43e037b27648 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Nov 2006 21:52:38 +0000 Subject: [PATCH] no_media/ringback tweaks git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3461 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_types.h | 3 ++- .../mod_bridgecall/mod_bridgecall.c | 25 ++++++++++++++----- src/mod/endpoints/mod_sofia/mod_sofia.c | 5 ++-- src/switch_ivr.c | 15 +++++++---- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index e553d54605..e489eb985e 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -465,7 +465,8 @@ typedef enum { CF_CONTROLLED = (1 << 12), CF_NOMEDIA = (1 << 13), CF_SUSPEND = (1 << 14), - CF_EVENT_PARSE = (1 << 15) + CF_EVENT_PARSE = (1 << 15), + CF_NO_INDICATE = (1 << 16) } switch_channel_flag_t; diff --git a/src/mod/applications/mod_bridgecall/mod_bridgecall.c b/src/mod/applications/mod_bridgecall/mod_bridgecall.c index 89e16549c6..c25003149c 100644 --- a/src/mod/applications/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/applications/mod_bridgecall/mod_bridgecall.c @@ -42,6 +42,7 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) switch_core_session_t *peer_session; unsigned int timelimit = 60; char *var; + uint8_t no_media_bridge = 0; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; caller_channel = switch_core_session_get_channel(session); @@ -50,9 +51,14 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) { timelimit = atoi(var); } - - if ((var = switch_channel_get_variable(caller_channel, "no_media"))) { - switch_channel_set_flag(caller_channel, CF_NOMEDIA); + + if ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var)) { + if (!switch_channel_test_flag(caller_channel, CF_ANSWERED) && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) { + switch_channel_set_flag(caller_channel, CF_NOMEDIA); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already up, delaying point-to-point mode 'till both legs are up.\n"); + no_media_bridge = 1; + } } if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) { @@ -61,10 +67,17 @@ static void audio_bridge_function(switch_core_session_t *session, char *data) switch_channel_hangup(caller_channel, cause); return; } else { - if (switch_channel_test_flag(caller_channel, CF_NOMEDIA)) { - switch_ivr_signal_bridge(session, peer_session); + if (no_media_bridge) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Redirecting media to point-to-point mode.\n"); + switch_ivr_nomedia(switch_core_session_get_uuid(session), SMF_FORCE); + switch_ivr_nomedia(switch_core_session_get_uuid(peer_session), SMF_FORCE); + switch_ivr_signal_bridge(session, peer_session); } else { - switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); + if (switch_channel_test_flag(caller_channel, CF_NOMEDIA)) { + switch_ivr_signal_bridge(session, peer_session); + } else { + switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); + } } } } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 6e1c949813..7126ec6144 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2441,9 +2441,10 @@ static void pass_sdp(private_object_t *tech_pvt, char *sdp) if (!switch_channel_get_variable(other_channel, SWITCH_B_SDP_VARIABLE)) { switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp); } + if (!switch_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && ( switch_channel_test_flag(other_channel, CF_OUTBOUND) && - switch_channel_test_flag(other_channel, CF_NOMEDIA) && + //switch_channel_test_flag(other_channel, CF_NOMEDIA) && switch_channel_test_flag(channel, CF_OUTBOUND) && switch_channel_test_flag(channel, CF_NOMEDIA))) { switch_ivr_nomedia(val, SMF_FORCE); @@ -2526,7 +2527,7 @@ static void sip_i_state(int status, break; case nua_callstate_proceeding: if (channel) { - if (status == 180) { + if (status == 180 && !(switch_channel_test_flag(channel, CF_NO_INDICATE))) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) { switch_core_session_message_t msg; diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 9286fe078b..908fc3b0d3 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -2443,6 +2443,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess peer_channels[i] = switch_core_session_get_channel(peer_sessions[i]); assert(peer_channels[i] != NULL); + //switch_channel_set_flag(peer_channels[i], CF_NO_INDICATE); + if (table == &noop_state_handler) { table = NULL; } else if (!table) { @@ -2501,7 +2503,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess switch_channel_pre_answer(caller_channel); } - if (session && !switch_channel_test_flag(caller_channel, CF_NOMEDIA)) { + if (session && (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA))) { read_codec = switch_core_session_get_read_codec(session); assert(read_codec != NULL); @@ -2527,6 +2529,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (ringback_data) { char *tmp_data = NULL; + switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0); switch_buffer_create_dynamic(&ringback.loop_buffer, 512, 1024, 0); @@ -2581,7 +2584,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } } } - + while ((!caller_channel || switch_channel_ready(caller_channel)) && check_channel_status(peer_channels, peer_sessions, and_argc, &idx, file, key, ringback_data)) { @@ -2603,13 +2606,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } /* read from the channel while we wait if the audio is up on it */ - if (session && !switch_channel_test_flag(caller_channel, CF_NOMEDIA) && + if (session && (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA)) && (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA))) { switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0); if (!SWITCH_READ_ACCEPTABLE(status)) { break; } + if (read_frame && !pass && !switch_test_flag(read_frame, SFF_CNG) && read_frame->datalen > 1) { if (ringback.fh) { uint8_t abuf[1024]; @@ -2653,7 +2657,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess break; } } - } + } + if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) { break; } @@ -2674,7 +2679,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess idx = IDX_CANCEL; } - if (session && !switch_channel_test_flag(caller_channel, CF_NOMEDIA)) { + if (session && (ringback_data || !switch_channel_test_flag(caller_channel, CF_NOMEDIA))) { switch_core_session_reset(session); }