diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 80a06ebc84..d4a908f488 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -151,11 +151,17 @@ SWITCH_DECLARE(switch_status) switch_ivr_speak_text(switch_core_session *session \param session one session \param peer_session the other session \param timelimit maximum number of seconds to wait for both channels to be answered + \param dtmf_callback code to execute if any dtmf is dialed during the bridge + \param session_data data to pass to the DTMF callback for session + \param peer_session_data data to pass to the DTMF callback for peer_session \return SWITCH_STATUS_SUCCESS if all is well */ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_session *session, switch_core_session *peer_session, - unsigned int timelimit); + unsigned int timelimit, + switch_dtmf_callback_function dtmf_callback, + void *session_data, + void *peer_session_data); /** @} */ diff --git a/src/mod/applications/mod_bridgecall/mod_bridgecall.c b/src/mod/applications/mod_bridgecall/mod_bridgecall.c index 89051a02e4..1a532084ad 100644 --- a/src/mod/applications/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/applications/mod_bridgecall/mod_bridgecall.c @@ -69,7 +69,7 @@ static void audio_bridge_function(switch_core_session *session, char *data) switch_channel_hangup(caller_channel); return; } else { - switch_ivr_multi_threaded_bridge(session, peer_session, timelimit); + switch_ivr_multi_threaded_bridge(session, peer_session, timelimit, NULL, NULL, NULL); } } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 497394dd67..fb4238fe0f 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -692,7 +692,9 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) struct switch_core_thread_session *data = obj; int *stream_id_p; int stream_id = 0, ans_a = 0, ans_b = 0; - + switch_dtmf_callback_function dtmf_callback; + void *user_data; + switch_channel *chan_a, *chan_b; switch_frame *read_frame; switch_core_session *session_a, *session_b; @@ -701,6 +703,9 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) session_b = data->objs[1]; stream_id_p = data->objs[2]; + dtmf_callback = data->objs[3]; + user_data = data->objs[4]; + if (stream_id_p) { stream_id = *stream_id_p; } @@ -745,6 +750,14 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) char dtmf[128]; switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf)); switch_core_session_send_dtmf(session_b, dtmf); + + if (dtmf_callback) { + if (dtmf_callback(session_a, dtmf, user_data, 0) != SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s ended call via DTMF\n", switch_channel_get_name(chan_a)); + data->running = -1; + break; + } + } } /* read audio from 1 channel and write it to the other */ @@ -829,7 +842,13 @@ static const switch_state_handler_table audio_bridge_caller_state_handlers = { SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_session *session, switch_core_session *peer_session, - unsigned int timelimit) + unsigned int timelimit, + switch_dtmf_callback_function dtmf_callback, + void *session_data, + void *peer_session_data) + + + { struct switch_core_thread_session this_audio_thread, other_audio_thread; switch_channel *caller_channel, *peer_channel; @@ -847,11 +866,16 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi other_audio_thread.objs[0] = session; other_audio_thread.objs[1] = peer_session; other_audio_thread.objs[2] = &stream_id; + other_audio_thread.objs[3] = dtmf_callback; + other_audio_thread.objs[4] = session_data; + other_audio_thread.running = 5; this_audio_thread.objs[0] = peer_session; this_audio_thread.objs[1] = session; this_audio_thread.objs[2] = &stream_id; + this_audio_thread.objs[3] = dtmf_callback; + this_audio_thread.objs[4] = peer_session_data; this_audio_thread.running = 2;