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
=== ===

@ -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;
@ -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