Formatting DTMF as a string
a '+' separated list of DTMF strings Each element in the list can contain an @ followed by a duration in ms. e.g. 1234@250+4321@500 sends the digits 1 2 3 4 at a rate of 250ms then 4 3 2 1 at a rate of 500 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7193 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7accbe103f
commit
3a5a239846
|
@ -427,6 +427,7 @@ SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(switch_channel_t *channel)
|
|||
\return SWITCH_STATUS_SUCCESS if successful
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *channel, const switch_dtmf_t *dtmf);
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string);
|
||||
|
||||
/*!
|
||||
\brief Retrieve DTMF digits from a given channel
|
||||
|
|
|
@ -845,6 +845,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_waitfor_write(_In_ switch_co
|
|||
\return SWITCH_STATUS_SUCCESS if the dtmf was written
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf);
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string);
|
||||
|
||||
/*!
|
||||
\brief RECV DTMF on a session
|
||||
|
|
|
@ -2647,20 +2647,6 @@ static switch_status_t conf_api_sub_dtmf(conference_member_t * member, switch_st
|
|||
{
|
||||
switch_event_t *event;
|
||||
char *dtmf = (char *) data;
|
||||
char *p;
|
||||
switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
|
||||
int tmp;
|
||||
|
||||
if ((p = strchr(dtmf, '+'))) {
|
||||
tmp = atoi(p);
|
||||
if (tmp > 0) {
|
||||
if (member->orig_read_codec && member->orig_read_codec->implementation) {
|
||||
_dtmf.duration = tmp * (member->orig_read_codec->implementation->samples_per_second / 1000);
|
||||
} else {
|
||||
_dtmf.duration = tmp * (member->conference->rate / 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (member == NULL) {
|
||||
stream->write_function(stream, "Invalid member!\n");
|
||||
|
@ -2676,12 +2662,7 @@ static switch_status_t conf_api_sub_dtmf(conference_member_t * member, switch_st
|
|||
switch_mutex_lock(member->flag_mutex);
|
||||
switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
|
||||
|
||||
p = dtmf;
|
||||
while(p && *p && is_dtmf(*p)) {
|
||||
_dtmf.digit = *p;
|
||||
switch_core_session_send_dtmf(member->session, &_dtmf);
|
||||
p++;
|
||||
}
|
||||
switch_core_session_send_dtmf_string(member->session, (char *)data);
|
||||
|
||||
switch_mutex_unlock(member->flag_mutex);
|
||||
|
||||
|
|
|
@ -181,17 +181,15 @@ SWITCH_STANDARD_APP(break_function)
|
|||
SWITCH_STANDARD_APP(queue_dtmf_function)
|
||||
{
|
||||
switch_channel_t *channel;
|
||||
char *p;
|
||||
switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
|
||||
channel = switch_core_session_get_channel(session);
|
||||
switch_channel_queue_dtmf_string(channel, (const char *) data);
|
||||
|
||||
}
|
||||
|
||||
if (!switch_strlen_zero(data)) {
|
||||
channel = switch_core_session_get_channel(session);
|
||||
switch_assert(channel != NULL);
|
||||
for (p = (char *)data; p && *p; p++) {
|
||||
dtmf.digit = *p;
|
||||
switch_channel_queue_dtmf(channel, &dtmf);
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(send_dtmf_function)
|
||||
{
|
||||
switch_core_session_send_dtmf_string(session, (const char *) data);
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(transfer_function)
|
||||
|
@ -1583,6 +1581,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
|
|||
SWITCH_ADD_APP(app_interface, "deflect", "Send call deflect", "Send a call deflect.", deflect_function, "<deflect_data>", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "reject", "Send session reject (depricated)", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "send_dtmf", "Send dtmf to be sent", "Send dtmf to be sent from a session", send_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
|
||||
SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
|
||||
|
|
|
@ -249,6 +249,51 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
|
|||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string)
|
||||
{
|
||||
char *p;
|
||||
switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
|
||||
int sent = 0, dur;
|
||||
char *string;
|
||||
int i, argc;
|
||||
char *argv[256];
|
||||
|
||||
|
||||
switch_assert(channel != NULL);
|
||||
|
||||
if (switch_strlen_zero(dtmf_string)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
string = switch_core_session_strdup(channel->session, dtmf_string);
|
||||
argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
|
||||
dur = SWITCH_DEFAULT_DTMF_DURATION / 8;
|
||||
if ((p = strchr(argv[i], '@'))) {
|
||||
*p++ = '\0';
|
||||
if ((dur = atoi(p)) > 50) {
|
||||
dtmf.duration = dur * 8;
|
||||
}
|
||||
}
|
||||
|
||||
for (p = argv[i]; p && *p; p++) {
|
||||
if (is_dtmf(*p)) {
|
||||
dtmf.digit = *p;
|
||||
if (switch_channel_queue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Queue dtmf\ndigit=%c ms=%u samples=%u\n",
|
||||
switch_channel_get_name(channel), dtmf.digit, dur, dtmf.duration);
|
||||
sent++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sent ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *channel, switch_dtmf_t *dtmf)
|
||||
{
|
||||
switch_event_t *event;
|
||||
|
|
|
@ -954,3 +954,54 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
|
|||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string)
|
||||
{
|
||||
char *p;
|
||||
switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
|
||||
int sent = 0, dur;
|
||||
char *string;
|
||||
int i, argc;
|
||||
char *argv[256];
|
||||
|
||||
|
||||
switch_assert(session != NULL);
|
||||
|
||||
if (switch_strlen_zero(dtmf_string)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
string = switch_core_session_strdup(session, dtmf_string);
|
||||
argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (argc) {
|
||||
switch_channel_pre_answer(session->channel);
|
||||
}
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
|
||||
dur = SWITCH_DEFAULT_DTMF_DURATION / 8;
|
||||
if ((p = strchr(argv[i], '@'))) {
|
||||
*p++ = '\0';
|
||||
if ((dur = atoi(p)) > 50) {
|
||||
dtmf.duration = dur * 8;
|
||||
}
|
||||
}
|
||||
|
||||
for (p = argv[i]; p && *p; p++) {
|
||||
if (is_dtmf(*p)) {
|
||||
dtmf.digit = *p;
|
||||
if (switch_core_session_send_dtmf(session, &dtmf) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s send dtmf\ndigit=%c ms=%u samples=%u\n",
|
||||
switch_channel_get_name(session->channel), dtmf.digit, dur, dtmf.duration);
|
||||
sent++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sent ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue