freetdm: Added dtmfdetect duration option

This commit is contained in:
David Yat Sin 2012-01-04 11:16:29 -05:00
parent 89c639743d
commit badc80ad3e
4 changed files with 26 additions and 5 deletions

View File

@ -4574,7 +4574,7 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span_channels(ftdm_span_t *span, const
ftdm_assert_return(span->fio != NULL, FTDM_EINVAL, "span with no I/O configured\n");
ftdm_assert_return(span->fio->configure_span != NULL, FTDM_NOTIMPL, "span I/O with no channel configuration implemented\n");
currindex = span->chan_count;
currindex = span->chan_count;
*configured = 0;
*configured = span->fio->configure_span(span, str, chan_config->type, chan_config->name, chan_config->number);
if (!*configured) {
@ -4604,8 +4604,10 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span_channels(ftdm_span_t *span, const
}
if (chan_config->debugdtmf) {
span->channels[chan_index]->dtmfdbg.requested = 1;
span->channels[chan_index]->dtmfdbg.requested = 1;
}
span->channels[chan_index]->dtmfdetect.duration_ms = chan_config->dtmfdetect_ms;
}
return FTDM_SUCCESS;
@ -4628,6 +4630,7 @@ static ftdm_status_t load_config(void)
memset(&chan_config, 0, sizeof(chan_config));
sprintf(chan_config.group_name, "__default");
chan_config.dtmfdetect_ms = 45;
if (!ftdm_config_open_file(&cfg, cfg_name)) {
return FTDM_FAIL;
@ -4802,6 +4805,10 @@ static ftdm_status_t load_config(void)
} else if (!strcasecmp(var, "debugdtmf")) {
chan_config.debugdtmf = ftdm_true(val);
ftdm_log(FTDM_LOG_DEBUG, "Setting debugdtmf to '%s'\n", chan_config.debugdtmf ? "yes" : "no");
} else if (!strncasecmp(var, "dtmfdetect_ms", sizeof("dtmfdetect_ms")-1)) {
if (sscanf(val, "%d", &(chan_config.dtmfdetect_ms)) != 1) {
ftdm_log(FTDM_LOG_ERROR, "invalid dtmfdetect_ms: '%s'\n", val);
}
} else if (!strncasecmp(var, "iostats", sizeof("iostats")-1)) {
if (ftdm_true(val)) {
chan_config.iostats = FTDM_TRUE;

View File

@ -471,6 +471,7 @@ static FIO_CONFIGURE_FUNCTION(wanpipe_configure)
wp_globals.ring_off_ms = num;
}
}
}
return FTDM_SUCCESS;
@ -1475,13 +1476,19 @@ static __inline__ ftdm_status_t wanpipe_channel_process_event(ftdm_channel_t *fc
if (tdm_api->wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_PRESENT) {
ftdm_set_flag(fchan, FTDM_CHANNEL_MUTE);
fchan->dtmfdetect.start_time = ftdm_current_time_in_ms();
}
if (tdm_api->wp_tdm_cmd.event.wp_tdm_api_event_dtmf_type == WAN_EC_TONE_STOP) {
ftdm_clear_flag(fchan, FTDM_CHANNEL_MUTE);
if (ftdm_test_flag(fchan, FTDM_CHANNEL_INUSE)) {
ftdm_log_chan(fchan, FTDM_LOG_DEBUG, "Queuing wanpipe DTMF: %c\n", tmp_dtmf[0]);
ftdm_channel_queue_dtmf(fchan, tmp_dtmf);
ftdm_time_t diff = ftdm_current_time_in_ms() - fchan->dtmfdetect.start_time;
if (diff > fchan->dtmfdetect.duration_ms) {
ftdm_log_chan(fchan, FTDM_LOG_DEBUG, "Queuing wanpipe DTMF: %c (duration:%d min:%d)\n", tmp_dtmf[0], diff, fchan->dtmfdetect.duration_ms);
ftdm_channel_queue_dtmf(fchan, tmp_dtmf);
} else {
ftdm_log_chan(fchan, FTDM_LOG_DEBUG, "Ignoring wanpipe DTMF: %c (duration:%d min:%d)\n", tmp_dtmf[0], diff, fchan->dtmfdetect.duration_ms);
}
}
}
}

View File

@ -479,7 +479,7 @@ typedef enum {
FTDM_STR2ENUM_P(ftdm_str2ftdm_trunk_type, ftdm_trunk_type2str, ftdm_trunk_type_t)
/*! \brief Basic channel configuration provided to ftdm_configure_span_channels */
typedef struct ftdm_channel_config {
typedef struct ftdm_channel_config {
char name[FTDM_MAX_NAME_STR_SZ];
char number[FTDM_MAX_NUMBER_STR_SZ];
char group_name[FTDM_MAX_NAME_STR_SZ];
@ -487,6 +487,7 @@ typedef struct ftdm_channel_config {
float rxgain;
float txgain;
uint8_t debugdtmf;
uint32_t dtmfdetect_ms;
uint8_t iostats;
} ftdm_channel_config_t;

View File

@ -359,6 +359,11 @@ typedef struct {
ftdm_mutex_t *mutex;
} ftdm_dtmf_debug_t;
typedef struct {
uint32_t duration_ms;
ftdm_time_t start_time;
} ftdm_dtmf_detect_t;
/* 2^8 table size, one for each byte (sample) value */
#define FTDM_GAINS_TABLE_SIZE 256
struct ftdm_channel {
@ -438,6 +443,7 @@ struct ftdm_channel {
ftdm_timer_id_t hangup_timer;
ftdm_channel_iostats_t iostats;
ftdm_dtmf_debug_t dtmfdbg;
ftdm_dtmf_detect_t dtmfdetect;
ftdm_io_dump_t rxdump;
ftdm_io_dump_t txdump;
ftdm_interrupt_t *state_completed_interrupt; /*!< Notify when a state change is completed */