]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add dtmf callback to brige (not tested good luck)
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 1 Mar 2006 05:52:42 +0000 (05:52 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 1 Mar 2006 05:52:42 +0000 (05:52 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@710 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/mod/applications/mod_bridgecall/mod_bridgecall.c
src/switch_ivr.c

index 80a06ebc84d9b57320a14a89e9072dcbed7ae794..d4a908f4888531d57b5dbb2f8dc9eab16bd84ba1 100644 (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);
 
 /** @} */
 
index 89051a02e4042c5071469f27cef16cde5fdf5db7..1a532084adda77f1b44697d6dc0b0b2f185f59c0 100644 (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);
        }
 }
 
index 497394dd6714644d5063b5dd167da8779d8ed93e..fb4238fe0f9d1700521bcf678ef9421a2aa23bee 100644 (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;