]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
IVR groundwork (move playback into the core and add timing option)
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 26 Jan 2006 17:57:25 +0000 (17:57 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 26 Jan 2006 17:57:25 +0000 (17:57 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@447 d0543943-73ff-0310-b7d9-9358b9ac24b2

Makefile.am
Makefile.in
conf/extensions.conf
src/include/switch_types.h
src/mod/applications/mod_playback/mod_playback.c

index 1786aff3afe0a3adba2ec4fc25ae679626449425..858b66520f7c9928b43a60c4bb19c4e06d93cf56 100644 (file)
@@ -55,6 +55,7 @@ src/include/switch_utils.h \
 src/include/switch_caller.h \
 src/include/switch_buffer.h \
 src/include/switch_event.h \
+src/include/switch_ivr.h\
 src/switch_buffer.c \
 src/switch_caller.c \
 src/switch_channel.c \
@@ -65,7 +66,8 @@ src/switch_loadable_module.c \
 src/switch_mutex.c \
 src/switch_utils.c \
 src/switch_event.c \
-src/switch_resample.c
+src/switch_resample.c \
+src/switch_ivr.c
 
 
 
@@ -86,7 +88,8 @@ library_include_HEADERS =     src/include/switch.h \
                                src/include/switch_caller.h \
                                src/include/switch_buffer.h \
                                src/include/switch_event.h \
-                               src/include/switch_resample.h
+                               src/include/switch_resample.h \
+                               src/include/switch_ivr.h
 
 
 lib_LTLIBRARIES                = libfreeswitch.la
index be68e364ec7b8d1319819b01dfb60b7490a899de..e25f729bc99b0e42a8208d283bc5c418b3234a11 100644 (file)
@@ -79,7 +79,8 @@ am_libfreeswitch_la_OBJECTS = libfreeswitch_la-switch_buffer.lo \
        libfreeswitch_la-switch_mutex.lo \
        libfreeswitch_la-switch_utils.lo \
        libfreeswitch_la-switch_event.lo \
-       libfreeswitch_la-switch_resample.lo
+       libfreeswitch_la-switch_resample.lo \
+       libfreeswitch_la-switch_ivr.lo
 libfreeswitch_la_OBJECTS = $(am_libfreeswitch_la_OBJECTS)
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
 PROGRAMS = $(bin_PROGRAMS)
@@ -263,6 +264,7 @@ src/include/switch_utils.h \
 src/include/switch_caller.h \
 src/include/switch_buffer.h \
 src/include/switch_event.h \
+src/include/switch_ivr.h\
 src/switch_buffer.c \
 src/switch_caller.c \
 src/switch_channel.c \
@@ -273,7 +275,8 @@ src/switch_loadable_module.c \
 src/switch_mutex.c \
 src/switch_utils.c \
 src/switch_event.c \
-src/switch_resample.c
+src/switch_resample.c \
+src/switch_ivr.c
 
 
 #bindir = $(PREFIX)/bin
@@ -293,7 +296,8 @@ library_include_HEADERS = src/include/switch.h \
                                src/include/switch_caller.h \
                                src/include/switch_buffer.h \
                                src/include/switch_event.h \
-                               src/include/switch_resample.h
+                               src/include/switch_resample.h \
+                               src/include/switch_ivr.h
 
 lib_LTLIBRARIES = libfreeswitch.la
 libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g  
@@ -436,6 +440,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_console.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_core.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_event.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_ivr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_loadable_module.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_mutex.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_resample.Plo@am__quote@
@@ -539,6 +544,13 @@ libfreeswitch_la-switch_resample.lo: src/switch_resample.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_resample.lo `test -f 'src/switch_resample.c' || echo '$(srcdir)/'`src/switch_resample.c
 
+libfreeswitch_la-switch_ivr.lo: src/switch_ivr.c
+@am__fastdepCC_TRUE@   if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -MT libfreeswitch_la-switch_ivr.lo -MD -MP -MF "$(DEPDIR)/libfreeswitch_la-switch_ivr.Tpo" -c -o libfreeswitch_la-switch_ivr.lo `test -f 'src/switch_ivr.c' || echo '$(srcdir)/'`src/switch_ivr.c; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/libfreeswitch_la-switch_ivr.Tpo" "$(DEPDIR)/libfreeswitch_la-switch_ivr.Plo"; else rm -f "$(DEPDIR)/libfreeswitch_la-switch_ivr.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/switch_ivr.c' object='libfreeswitch_la-switch_ivr.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_ivr.lo `test -f 'src/switch_ivr.c' || echo '$(srcdir)/'`src/switch_ivr.c
+
 freeswitch-switch.o: src/switch.c
 @am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(freeswitch_CFLAGS) $(CFLAGS) -MT freeswitch-switch.o -MD -MP -MF "$(DEPDIR)/freeswitch-switch.Tpo" -c -o freeswitch-switch.o `test -f 'src/switch.c' || echo '$(srcdir)/'`src/switch.c; \
 @am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/freeswitch-switch.Tpo" "$(DEPDIR)/freeswitch-switch.Po"; else rm -f "$(DEPDIR)/freeswitch-switch.Tpo"; exit 1; fi
index cf7554688dcef8e7f609ed9c6c267daf18df5367..7decb11570f14f899455cb52040ace0d39c1f643 100644 (file)
@@ -1,4 +1,9 @@
 [extensions]
 
 1000 => playback /tmp/siriusraw.raw
-888 => bridge woomera/888@10.200.68.194
+
+; to time from a timer instead of from the input stream use
+; 1000 => playback /tmp/siriusraw.raw soft
+
+; call the freeswitch conference
+888 => bridge iax/guest@10.200.68.194/888
index 3494ab245f8786956b61c9bc16e489760d4a18a7..5607c76c49717fa96e4f1d4365fe2426cb088764 100644 (file)
@@ -45,6 +45,18 @@ extern "C" {
 #define SWITCH_MAX_CODECS 30
 
 
+/*!
+  \enum switch_ivr_option_t
+  \brief Possible options related to ivr functions
+<pre>
+    SWITCH_IVR_OPTION_SYNC  - synchronous (do everyting in the forground)
+
+</pre>
+ */
+typedef enum {
+       SWITCH_IVR_OPTION_SYNC = (1 << 0)
+} switch_ivr_option_t;
+       
 /*!
   \enum switch_core_session_message_t
   \brief Possible types of messages for inter-session communication
@@ -354,6 +366,7 @@ typedef switch_status (*switch_waitfor_read_hook)(switch_core_session *, int, in
 typedef switch_status (*switch_waitfor_write_hook)(switch_core_session *, int, int);
 typedef switch_status (*switch_send_dtmf_hook)(switch_core_session *, char *);
 typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen);
+typedef switch_status (*switch_dtmf_callback_function)(switch_core_session *session, char *dtmf);
 
 /* things we don't deserve to know about */
 
index 4bdefef3d4f7593da647c0ee9c11ffe854d3f011..b1aafcc4c4ece9f6714dca391b0c4812de8a4edc 100644 (file)
  *
  */
 #include <switch.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <switch_ivr.h>
 
 
-static const char modname[] = "mod_playback";
 
+static const char modname[] = "mod_playback";
 
-void playback_function(switch_core_session *session, char *data)
+/*
+  dtmf handler function you can hook up to be executed when a digit is dialed during playback 
+   if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
+*/
+static switch_status on_dtmf(switch_core_session *session, char *dtmf)
 {
-       switch_channel *channel;
-       short buf[960];
-       char dtmf[128];
-       int interval = 0, samples = 0;
-       size_t len = 0, ilen = 0;
-       switch_frame write_frame;
-       switch_timer timer;
-       switch_core_thread_session thread_session;
-       switch_codec codec;
-       switch_memory_pool *pool = switch_core_session_get_pool(session);
-       switch_file_handle fh;
-       char *codec_name;
-       int x;
-       int stream_id;
-
-       channel = switch_core_session_get_channel(session);
-       assert(channel != NULL);
+       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Digits %s\n", dtmf);
 
-       if (switch_core_file_open(&fh,
-                                                         data,
-                                                         SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-                                                         switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-               switch_channel_hangup(channel);
-               return;
+       if (*dtmf == '*') {
+               return SWITCH_STATUS_FALSE;
        }
+       
+       return SWITCH_STATUS_SUCCESS;
+}
 
-       switch_channel_answer(channel);
-
-       write_frame.data = buf;
-       write_frame.buflen = sizeof(buf);
-
-
-       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s %dhz %d channels\n", data, fh.samplerate, fh.channels);
 
-       interval = 20;
-       samples = (fh.samplerate / 50) * fh.channels;
-       len = samples * 2;
+void playback_function(switch_core_session *session, char *data)
+{
+       switch_channel *channel;
+       char *timer_name = NULL;
+       char *file_name = NULL;
 
-       codec_name = "L16";
+       file_name = switch_core_session_strdup(session, data);
 
-       if (switch_core_codec_init(&codec,
-                                                          codec_name,
-                                                          fh.samplerate,
-                                                          interval,
-                                                          fh.channels,
-                                                          SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-                                                          NULL, pool) == SWITCH_STATUS_SUCCESS) {
-               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
-               write_frame.codec = &codec;
-       } else {
-               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n",
-                                                         codec_name, fh.samplerate, fh.channels, interval);
-               switch_core_file_close(&fh);
-               switch_channel_hangup(channel);
-               return;
+       if ((timer_name = strchr(file_name, ' '))) {
+               *timer_name++ = '\0';
        }
 
-       if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
-               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n");
-               switch_core_codec_destroy(&codec);
-               switch_core_file_close(&fh);
-               switch_channel_hangup(channel);
-               return;
-       }
-       write_frame.rate = fh.samplerate;
-       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
+       channel = switch_core_session_get_channel(session);
+    assert(channel != NULL);
 
-       /* start a thread to absorb incoming audio */
-       for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
-               switch_core_service_session(session, &thread_session, stream_id);
-       }
-       ilen = samples;
-       while (switch_channel_get_state(channel) == CS_EXECUTE) {
-               int done = 0;
-
-               if (switch_channel_has_dtmf(channel)) {
-                       switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
-                       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF [%s]\n", dtmf);
-
-                       switch (*dtmf) {
-                       case '*':
-                               done = 1;
-                               break;
-                       default:
-                               break;
-                       }
-               }
-
-               if (done) {
-                       break;
-               }
-
-               switch_core_file_read(&fh, buf, &ilen);
-
-               if (ilen <= 0) {
-                       break;
-               }
-
-               write_frame.datalen = ilen * 2;
-               write_frame.samples = (int) ilen;
-#ifdef SWAP_LINEAR
-               switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);
-#endif
-
-               for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
-                       if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
-                               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n");
-                               done = 1;
-                               break;
-                       }
-
-                       if (done) {
-                               break;
-                       }
-               }
-
-               if ((x = switch_core_timer_next(&timer)) < 0) {
-                       break;
-               }
+       if (switch_ivr_play_file(session, file_name, timer_name, on_dtmf) != SWITCH_STATUS_SUCCESS) {
+               switch_channel_hangup(channel);
        }
-
-       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "done playing file\n");
-       switch_core_file_close(&fh);
-
-       //switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
-
-       switch_core_timer_destroy(&timer);
-
-       switch_core_codec_destroy(&codec);
-
-       //switch_channel_hangup(channel);
-
-       /* End the audio absorbing thread */
-       switch_core_thread_session_end(&thread_session);
-
+       
 }
 
 static const switch_application_interface playback_application_interface = {