]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add sync param to sleep so you can choose to sync audio or not on sleep (reswig to...
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 10 Dec 2008 00:48:24 +0000 (00:48 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 10 Dec 2008 00:48:24 +0000 (00:48 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10693 d0543943-73ff-0310-b7d9-9358b9ac24b2

12 files changed:
src/include/switch_cpp.h
src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/applications/mod_fax/mod_fax.c
src/mod/applications/mod_fifo/mod_fifo.c
src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_cpp.cpp
src/switch_ivr.c
src/switch_ivr_menu.c
src/switch_ivr_originate.c
src/switch_ivr_play_say.c

index ce64a2e04754da1ec1b67f6a5ca40129ac17d437..d06269b0d099dfd32b23f13f5349079f69285d08 100644 (file)
@@ -313,7 +313,7 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg);
         *
         */
                 SWITCH_DECLARE(int) streamFile(char *file, int starting_sample_count = 0);
-                SWITCH_DECLARE(int) sleep(int ms);
+                SWITCH_DECLARE(int) sleep(int ms, int sync=0);
 
        /** \brief flush any pending events
         */
index e0b7b7984f6e9456c8b457e94c2e3887fc6b0233..6cfb7dc5a03509823f48fc2aa8396324d8c5550d 100644 (file)
@@ -110,7 +110,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_next_event(switch_core_session_
   \param args arguements to pass for callbacks etc
   \return SWITCH_STATUS_SUCCESS if the channel is still up
 */
-SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_input_args_t *args);
+SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args);
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_input_args_t *args);
 
index 3bff7c73167500f88d8ecc5e207d9aabf40c5b57..5b27209df94c690922f15db7670449726b858490 100644 (file)
@@ -1307,7 +1307,7 @@ SWITCH_STANDARD_APP(sleep_function)
                
                switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
 
-               switch_ivr_sleep(session, ms, &args);
+               switch_ivr_sleep(session, ms, SWITCH_TRUE, &args);
        }
 }
 
index 58b7fbfe8adae6f7a7c252251ecb3592e155a483..dba54a52d7b45e1e432157cb901e25db198e14a3 100644 (file)
@@ -608,7 +608,7 @@ void process_fax(switch_core_session_t *session, const char *data, application_m
                goto done;
        }
 
-    switch_ivr_sleep(session, 250, NULL);
+    switch_ivr_sleep(session, 250, SWITCH_TRUE, NULL);
     
        while (switch_channel_ready(channel)) {
                int tx = 0;
index bd37c38569f64ba8992bfa983d9d67bea43d690f..e2f448a0cb22aa8250c4f0d2a078ae333da42bee 100644 (file)
@@ -1167,7 +1167,7 @@ SWITCH_STANDARD_APP(fifo_function)
                                if (announce) {
                                        switch_ivr_play_file(session, NULL, announce, NULL);
                                } else {
-                                       switch_ivr_sleep(session, 500, NULL);
+                                       switch_ivr_sleep(session, 500, SWITCH_TRUE, NULL);
                                }
 
                                switch_channel_set_variable(other_channel, "fifo_serviced_by", my_id);
index 75d88e4291a8151b417009bd5b150ff0b4ac58b6..97c3ead142b0297f00dc8caa02faa97a9a291c20 100644 (file)
@@ -1403,7 +1403,7 @@ static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t
                                        forward_file_path = switch_core_session_sprintf(session, "%s%smsg_%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str);
                                        TRY_CODE(create_file(session, profile, VM_RECORD_MESSAGE_MACRO, forward_file_path, &message_len, SWITCH_TRUE, NULL, NULL));
                                        if ((new_path = vm_merge_file(session, profile, forward_file_path, cbt->file_path))) {
-                                               switch_ivr_sleep(session, 1500, NULL);
+                                               switch_ivr_sleep(session, 1500, SWITCH_TRUE, NULL);
                                                forward_file_path = new_path;
                                        } else {
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error merging files\n");
@@ -1637,7 +1637,7 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro
        *global_buf = '\0';
 
        while (switch_channel_ready(channel)) {
-               switch_ivr_sleep(session, 100, NULL);
+               switch_ivr_sleep(session, 100, SWITCH_TRUE, NULL);
 
                switch (vm_check_state) {
                case VM_CHECK_START:
index db531e7a60c141cdee765a078ede1bcabf65b6b5..0e90c8719a03f18380e881166d245c8a627ff19d 100644 (file)
@@ -1723,7 +1723,8 @@ static JSBool session_sleep(JSContext * cx, JSObject * obj, uintN argc, jsval *
        switch_input_args_t args = { 0 };
        int32 ms = 0;
        jsval ret = JS_TRUE;
-
+       int sync;
+       
        METHOD_SANITY_CHECK();
        channel = switch_core_session_get_channel(jss->session);
        CHANNEL_SANITY_CHECK();
@@ -1755,12 +1756,16 @@ static JSBool session_sleep(JSContext * cx, JSObject * obj, uintN argc, jsval *
                }
        }
 
+       if (argc > 2) {
+               JS_ValueToInt32(cx, argv[2], &sync);
+       }
+
        cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE);
        cb_state.saveDepth = JS_SuspendRequest(cx);
        args.input_callback = dtmf_func;
        args.buf = bp;
        args.buflen = len;
-       switch_ivr_sleep(jss->session, ms, &args);
+       switch_ivr_sleep(jss->session, ms, sync, &args);
        JS_ResumeRequest(cx, cb_state.saveDepth);
        check_hangup_hook(jss, &ret);
        *rval = cb_state.ret;
index b4b87eaaa53d0bbd626c00d57a689a2946e4323b..ce47cbb965fbacbb6c05ca50c3966d6e9abc648d 100644 (file)
@@ -833,7 +833,7 @@ SWITCH_DECLARE(int) CoreSession::streamFile(char *file, int starting_sample_coun
 
 }
 
-SWITCH_DECLARE(int) CoreSession::sleep(int ms) {
+SWITCH_DECLARE(int) CoreSession::sleep(int ms, int sync) {
 
     switch_status_t status;
 
@@ -841,7 +841,7 @@ SWITCH_DECLARE(int) CoreSession::sleep(int ms) {
     sanity_check(-1);
        
     begin_allow_threads();
-    status = switch_ivr_sleep(session, ms, ap);
+    status = switch_ivr_sleep(session, ms, (switch_bool_t) sync, ap);
     end_allow_threads();
 
     return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
index 90dfac2bf78928b37ead8ec4e7ed8bc3feb928e6..b627252d9051ab98f3ee1a8c1e754a6e7e7f2ac5 100644 (file)
@@ -38,7 +38,7 @@
 #include <switch_ivr.h>
 #include "stfu.h"
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_input_args_t *args)
+SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
        switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -80,6 +80,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
                write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
                write_frame.datalen = imp.decoded_bytes_per_packet;
                write_frame.samples = write_frame.datalen / sizeof(int16_t);
+
+               if (!switch_channel_media_ready(channel)) {
+                       if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot establish media.\n");
+                               return SWITCH_STATUS_FALSE;
+                       }
+               }
        }
 
        cng_frame.data = data;
@@ -87,7 +94,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
        cng_frame.buflen = 2;
        switch_set_flag((&cng_frame), SFF_CNG);
 
-       if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) {
+       if (sync && !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
                switch_channel_audio_sync(channel);
        }
        
index f5b5b4719b86cfe5c42760af7b8469a322d9bfaa..42ce6ef4acbd94d6e53af8f59fbf2230246714ce 100644 (file)
@@ -529,7 +529,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s
                        }
                        errs++;
                        if (status == SWITCH_STATUS_SUCCESS) {
-                               status = switch_ivr_sleep(session, 1000, NULL);
+                               status = switch_ivr_sleep(session, 1000, SWITCH_FALSE, NULL);
                        }
                        /* breaks are ok too */
                        if (SWITCH_STATUS_IS_BREAK(status)) {
index b4d9df99b578620d5fb88c9f3e6e264ee914e0b2..e45c982b825643ef124b6543fae495967fcc199d 100644 (file)
@@ -91,7 +91,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void
                return NULL;
        }
        
-       switch_ivr_sleep(collect->session, 0, NULL);
+       switch_ivr_sleep(collect->session, 0, SWITCH_TRUE, NULL);
        
        if (!strcasecmp(collect->key, "exec")) {
                char *data;
@@ -951,7 +951,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                        if (try > 0) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Originate attempt %d/%d in %d ms\n", try + 1, retries, sleep_ms);
                                if (caller_channel) {
-                                       switch_ivr_sleep(session, sleep_ms, NULL);
+                                       switch_ivr_sleep(session, sleep_ms, SWITCH_TRUE, NULL);
                                } else {
                                        switch_yield(sleep_ms * 1000);
                                }
@@ -1749,11 +1749,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
        }
 
        if (*bleg) {
-               switch_ivr_sleep(*bleg, 0, NULL);
+               switch_ivr_sleep(*bleg, 0, SWITCH_TRUE, NULL);
        }
 
        if (session) {
-               switch_ivr_sleep(session, 0, NULL);
+               switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL);
        }
 
        if (var_event && var_event != ovars) {
index 523f9d0782fc57dc37930f80ae0b00f9ff0b3856..fe7a6b4b1a5eec48356ad40cfd02c8cf66ff9b47 100644 (file)
@@ -327,7 +327,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
                                                }
                                        }
 
-                                       switch_ivr_sleep(session, pause, NULL);
+                                       switch_ivr_sleep(session, pause, SWITCH_FALSE, NULL);
                                }
                        }