Clean up dsp.conf parsing

Review: https://reviewboard.asterisk.org/r/1434/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@335603 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/11.2
Paul Belanger 14 years ago
parent 2d18de5f8f
commit 2e2381341e

@ -34,6 +34,7 @@ Configuration Files:
- cdr.conf: [general] and [csv] sections - cdr.conf: [general] and [csv] sections
- dnsmgr.conf - dnsmgr.conf
- dsp.conf
SIP SIP
=== ===

@ -59,7 +59,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
enum gsamp_size { enum gsamp_size {
GSAMP_SIZE_NA = 183, /*!< North America - 350, 440, 480, 620, 950, 1400, 1800 Hz */ GSAMP_SIZE_NA = 183, /*!< North America - 350, 440, 480, 620, 950, 1400, 1800 Hz */
GSAMP_SIZE_CR = 188, /*!< Costa Rica, Brazil - Only care about 425 Hz */ GSAMP_SIZE_CR = 188, /*!< Costa Rica, Brazil - Only care about 425 Hz */
GSAMP_SIZE_UK = 160 /*!< UK disconnect goertzel feed - should trigger 400hz */ GSAMP_SIZE_UK = 160 /*!< UK disconnect goertzel feed - should trigger 400hz */
}; };
enum prog_mode { enum prog_mode {
@ -103,8 +103,8 @@ static struct progress {
int freqs[7]; int freqs[7];
} modes[] = { } modes[] = {
{ GSAMP_SIZE_NA, { 350, 440, 480, 620, 950, 1400, 1800 } }, /*!< North America */ { GSAMP_SIZE_NA, { 350, 440, 480, 620, 950, 1400, 1800 } }, /*!< North America */
{ GSAMP_SIZE_CR, { 425 } }, /*!< Costa Rica, Brazil */ { GSAMP_SIZE_CR, { 425 } }, /*!< Costa Rica, Brazil */
{ GSAMP_SIZE_UK, { 350, 400, 440 } }, /*!< UK */ { GSAMP_SIZE_UK, { 350, 400, 440 } }, /*!< UK */
}; };
/*!\brief This value is the minimum threshold, calculated by averaging all /*!\brief This value is the minimum threshold, calculated by averaging all
@ -117,26 +117,26 @@ static struct progress {
#define DEFAULT_THRESHOLD 512 #define DEFAULT_THRESHOLD 512
enum busy_detect { enum busy_detect {
BUSY_PERCENT = 10, /*!< The percentage difference between the two last silence periods */ BUSY_PERCENT = 10, /*!< The percentage difference between the two last silence periods */
BUSY_PAT_PERCENT = 7, /*!< The percentage difference between measured and actual pattern */ BUSY_PAT_PERCENT = 7, /*!< The percentage difference between measured and actual pattern */
BUSY_THRESHOLD = 100, /*!< Max number of ms difference between max and min times in busy */ BUSY_THRESHOLD = 100, /*!< Max number of ms difference between max and min times in busy */
BUSY_MIN = 75, /*!< Busy must be at least 80 ms in half-cadence */ BUSY_MIN = 75, /*!< Busy must be at least 80 ms in half-cadence */
BUSY_MAX =3100 /*!< Busy can't be longer than 3100 ms in half-cadence */ BUSY_MAX =3100 /*!< Busy can't be longer than 3100 ms in half-cadence */
}; };
/*! Remember last 15 units */ /*! Remember last 15 units */
#define DSP_HISTORY 15 #define DSP_HISTORY 15
#define TONE_THRESH 10.0 /*!< How much louder the tone should be than channel energy */ #define TONE_THRESH 10.0 /*!< How much louder the tone should be than channel energy */
#define TONE_MIN_THRESH 1e8 /*!< How much tone there should be at least to attempt */ #define TONE_MIN_THRESH 1e8 /*!< How much tone there should be at least to attempt */
/*! All THRESH_XXX values are in GSAMP_SIZE chunks (us = 22ms) */ /*! All THRESH_XXX values are in GSAMP_SIZE chunks (us = 22ms) */
enum gsamp_thresh { enum gsamp_thresh {
THRESH_RING = 8, /*!< Need at least 150ms ring to accept */ THRESH_RING = 8, /*!< Need at least 150ms ring to accept */
THRESH_TALK = 2, /*!< Talk detection does not work continuously */ THRESH_TALK = 2, /*!< Talk detection does not work continuously */
THRESH_BUSY = 4, /*!< Need at least 80ms to accept */ THRESH_BUSY = 4, /*!< Need at least 80ms to accept */
THRESH_CONGESTION = 4, /*!< Need at least 80ms to accept */ THRESH_CONGESTION = 4, /*!< Need at least 80ms to accept */
THRESH_HANGUP = 60, /*!< Need at least 1300ms to accept hangup */ THRESH_HANGUP = 60, /*!< Need at least 1300ms to accept hangup */
THRESH_RING2ANSWER = 300 /*!< Timeout from start of ring to answer (about 6600 ms) */ THRESH_RING2ANSWER = 300 /*!< Timeout from start of ring to answer (about 6600 ms) */
}; };
@ -433,7 +433,7 @@ static void ast_tone_detect_init(tone_detect_state_t *s, int freq, int duration,
/* If we want to remove tone, it is important to have block size not /* If we want to remove tone, it is important to have block size not
to exceed frame size. Otherwise by the moment tone is detected it is too late to exceed frame size. Otherwise by the moment tone is detected it is too late
to squelch it from previous frames. Block size is 20ms at the given sample rate.*/ to squelch it from previous frames. Block size is 20ms at the given sample rate.*/
s->block_size = (20 * sample_rate) / 1000; s->block_size = (20 * sample_rate) / 1000;
periods_in_block = s->block_size * freq / sample_rate; periods_in_block = s->block_size * freq / sample_rate;
@ -441,8 +441,9 @@ static void ast_tone_detect_init(tone_detect_state_t *s, int freq, int duration,
/* Make sure we will have at least 5 periods at target frequency for analisys. /* Make sure we will have at least 5 periods at target frequency for analisys.
This may make block larger than expected packet and will make squelching impossible This may make block larger than expected packet and will make squelching impossible
but at least we will be detecting the tone */ but at least we will be detecting the tone */
if (periods_in_block < 5) if (periods_in_block < 5) {
periods_in_block = 5; periods_in_block = 5;
}
/* Now calculate final block size. It will contain integer number of periods */ /* Now calculate final block size. It will contain integer number of periods */
s->block_size = periods_in_block * sample_rate / freq; s->block_size = periods_in_block * sample_rate / freq;
@ -493,8 +494,9 @@ static void ast_v21_detect_init(v21_detect_state_t *s, unsigned int sample_rate)
/* Make sure we will have at least 5 periods at target frequency for analisys. /* Make sure we will have at least 5 periods at target frequency for analisys.
This may make block larger than expected packet and will make squelching impossible This may make block larger than expected packet and will make squelching impossible
but at least we will be detecting the tone */ but at least we will be detecting the tone */
if (periods_in_block < 5) if (periods_in_block < 5) {
periods_in_block = 5; periods_in_block = 5;
}
/* Now calculate final block size. It will contain integer number of periods */ /* Now calculate final block size. It will contain integer number of periods */
s->block_size = periods_in_block * sample_rate / 1850; s->block_size = periods_in_block * sample_rate / 1850;
@ -1001,8 +1003,8 @@ static int mf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[]
/* Basic signal level and twist tests */ /* Basic signal level and twist tests */
hit = 0; hit = 0;
if (energy[best] >= BELL_MF_THRESHOLD && energy[second_best] >= BELL_MF_THRESHOLD if (energy[best] >= BELL_MF_THRESHOLD && energy[second_best] >= BELL_MF_THRESHOLD
&& energy[best] < energy[second_best]*BELL_MF_TWIST && energy[best] < energy[second_best]*BELL_MF_TWIST
&& energy[best] * BELL_MF_TWIST > energy[second_best]) { && energy[best] * BELL_MF_TWIST > energy[second_best]) {
/* Relative peak test */ /* Relative peak test */
hit = -1; hit = -1;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
@ -1061,8 +1063,9 @@ static int mf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[]
} }
/* Reinitialise the detector for the next block */ /* Reinitialise the detector for the next block */
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++) {
goertzel_reset(&s->td.mf.tone_out[i]); goertzel_reset(&s->td.mf.tone_out[i]);
}
s->td.mf.current_sample = 0; s->td.mf.current_sample = 0;
} }
@ -1603,10 +1606,11 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
} }
if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) { if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) {
if (dsp->digitmode & DSP_DIGITMODE_MF) if (dsp->digitmode & DSP_DIGITMODE_MF) {
digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
else } else {
digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
}
if (dsp->digit_state.current_digits) { if (dsp->digit_state.current_digits) {
int event = 0, event_len = 0; int event = 0, event_len = 0;
@ -1675,8 +1679,9 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
dsp->f.frametype = AST_FRAME_CONTROL; dsp->f.frametype = AST_FRAME_CONTROL;
dsp->f.subclass.integer = res; dsp->f.subclass.integer = res;
dsp->f.src = "dsp_progress"; dsp->f.src = "dsp_progress";
if (chan) if (chan) {
ast_queue_frame(chan, &dsp->f); ast_queue_frame(chan, &dsp->f);
}
break; break;
default: default:
ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
@ -1907,33 +1912,34 @@ int ast_dsp_get_tcount(struct ast_dsp *dsp)
static int _dsp_init(int reload) static int _dsp_init(int reload)
{ {
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
struct ast_config *cfg; struct ast_config *cfg;
struct ast_variable *v;
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
int cfg_threshold;
cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags); if ((cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
ast_verb(5, "Can't find dsp config file %s. Assuming default silencethreshold of %d.\n", CONFIG_FILE_NAME, DEFAULT_SILENCE_THRESHOLD);
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD;
return 0; return 0;
} }
if (cfg == CONFIG_STATUS_FILEUNCHANGED) { thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD;
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
return 0; return 0;
} }
if (cfg) { for (v = ast_variable_browse(cfg, "default"); v; v = v->next) {
const char *value; if (!strcasecmp(v->name, "silencethreshold")) {
if (sscanf(v->value, "%30d", &cfg_threshold) < 1) {
value = ast_variable_retrieve(cfg, "default", "silencethreshold"); ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", v->value);
if (value && sscanf(value, "%30d", &thresholds[THRESHOLD_SILENCE]) != 1) { } else if (cfg_threshold < 0) {
ast_verb(5, "%s: '%s' is not a valid silencethreshold value\n", CONFIG_FILE_NAME, value); ast_log(LOG_WARNING, "Invalid silence threshold '%d' specified, using default\n", cfg_threshold);
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD; } else {
} else if (!value) { thresholds[THRESHOLD_SILENCE] = cfg_threshold;
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD; }
} }
ast_config_destroy(cfg);
} }
ast_config_destroy(cfg);
return 0; return 0;
} }
@ -1951,4 +1957,3 @@ int ast_dsp_reload(void)
{ {
return _dsp_init(1); return _dsp_init(1);
} }

Loading…
Cancel
Save