add dtmf callback to brige (not tested good luck)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@710 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-03-01 05:52:42 +00:00
parent 4f06f7b8fd
commit ae4c68d880
3 changed files with 34 additions and 4 deletions

View File

@ -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);
/** @} */

View File

@ -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);
}
}

View File

@ -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;