mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-15 05:08:26 +00:00
add timeout to wait_for_silence
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8993 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
1bd99549e0
commit
cc63a0595a
@ -315,7 +315,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
||||
switch_input_args_t *args);
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, uint32_t silence_hits,
|
||||
uint32_t listen_hits, const char *file);
|
||||
uint32_t listen_hits, uint32_t timeout_ms, const char *file);
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args);
|
||||
|
||||
|
@ -2102,11 +2102,11 @@ SWITCH_STANDARD_APP(unhold_function)
|
||||
switch_ivr_unhold_uuid(switch_core_session_get_uuid(session));
|
||||
}
|
||||
|
||||
#define WAIT_FOR_SILENCE_SYNTAX "<silence_thresh> <silence_hits> <listen_hits> [<file>]"
|
||||
#define WAIT_FOR_SILENCE_SYNTAX "<silence_thresh> <silence_hits> <listen_hits> <timeout_ms> [<file>]"
|
||||
SWITCH_STANDARD_APP(wait_for_silence_function)
|
||||
{
|
||||
char *argv[4] = { 0 };
|
||||
uint32_t thresh, silence_hits, listen_hits;
|
||||
char *argv[5] = { 0 };
|
||||
uint32_t thresh, silence_hits, listen_hits, timeout_ms = 0;
|
||||
int argc;
|
||||
char *lbuf = NULL;
|
||||
|
||||
@ -2116,8 +2116,14 @@ SWITCH_STANDARD_APP(wait_for_silence_function)
|
||||
silence_hits = atoi(argv[1]);
|
||||
listen_hits = atoi(argv[2]);
|
||||
|
||||
if (argv[3]) {
|
||||
if ((timeout_ms = atoi(argv[3])) < 0) {
|
||||
timeout_ms = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (thresh > 0 && silence_hits > 0 && listen_hits > 0) {
|
||||
switch_ivr_wait_for_silence(session, thresh, silence_hits, listen_hits, argv[3]);
|
||||
switch_ivr_wait_for_silence(session, thresh, silence_hits, listen_hits, timeout_ms, argv[4]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1195,7 +1195,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, uint32_t silence_hits, uint32_t listen_hits, const char *file)
|
||||
SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh,
|
||||
uint32_t silence_hits, uint32_t listen_hits, uint32_t timeout_ms, const char *file)
|
||||
{
|
||||
uint32_t score, count = 0, j = 0;
|
||||
double energy = 0;
|
||||
@ -1213,9 +1214,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_
|
||||
int16_t *abuf = NULL;
|
||||
switch_frame_t write_frame = {0};
|
||||
switch_file_handle_t fh = {0};
|
||||
int32_t sample_count = 0;
|
||||
|
||||
switch_assert(read_codec);
|
||||
|
||||
if (timeout_ms) {
|
||||
sample_count = (read_codec->implementation->actual_samples_per_second / 1000) * timeout_ms;
|
||||
}
|
||||
|
||||
if (file) {
|
||||
if (switch_core_file_open(&fh,
|
||||
file,
|
||||
@ -1258,6 +1264,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_
|
||||
break;
|
||||
}
|
||||
|
||||
if (sample_count) {
|
||||
sample_count -= raw_codec.implementation->samples_per_frame;
|
||||
if (sample_count <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (abuf) {
|
||||
switch_size_t olen = raw_codec.implementation->samples_per_frame;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user