Go to the source code of this file.
Defines | |
#define | DSP_DIGITMODE_DTMF 0 |
#define | DSP_DIGITMODE_MF 1 |
#define | DSP_DIGITMODE_MUTECONF (1 << 9) |
#define | DSP_DIGITMODE_MUTEMAX (1 << 10) |
#define | DSP_DIGITMODE_NOQUELCH (1 << 8) |
#define | DSP_DIGITMODE_RELAXDTMF (1 << 11) |
#define | DSP_FEATURE_BUSY_DETECT (1 << 1) |
#define | DSP_FEATURE_CALL_PROGRESS (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION) |
#define | DSP_FEATURE_DTMF_DETECT (1 << 3) |
#define | DSP_FEATURE_FAX_DETECT (1 << 4) |
#define | DSP_FEATURE_SILENCE_SUPPRESS (1 << 0) |
#define | DSP_PROGRESS_BUSY (1 << 18) |
#define | DSP_PROGRESS_CONGESTION (1 << 19) |
#define | DSP_PROGRESS_RINGING (1 << 17) |
#define | DSP_PROGRESS_TALK (1 << 16) |
#define | DSP_TONE_STATE_BUSY 4 |
#define | DSP_TONE_STATE_DIALTONE 2 |
#define | DSP_TONE_STATE_HUNGUP 8 |
#define | DSP_TONE_STATE_RINGING 1 |
#define | DSP_TONE_STATE_SILENCE 0 |
#define | DSP_TONE_STATE_SPECIAL1 5 |
#define | DSP_TONE_STATE_SPECIAL2 6 |
#define | DSP_TONE_STATE_SPECIAL3 7 |
#define | DSP_TONE_STATE_TALKING 3 |
Functions | |
int | ast_dsp_busydetect (struct ast_dsp *dsp) |
Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been called. | |
int | ast_dsp_call_progress (struct ast_dsp *dsp, struct ast_frame *inf) |
Scans for progress indication in audio. | |
int | ast_dsp_digitdetect (struct ast_dsp *dsp, struct ast_frame *f) |
Return non-zero if DTMF hit was found. | |
int | ast_dsp_digitmode (struct ast_dsp *dsp, int digitmode) |
Set digit mode. | |
void | ast_dsp_digitreset (struct ast_dsp *dsp) |
Reset DTMF detector. | |
void | ast_dsp_free (struct ast_dsp *dsp) |
int | ast_dsp_get_tcount (struct ast_dsp *dsp) |
Get tcount (Threshold counter). | |
int | ast_dsp_get_tstate (struct ast_dsp *dsp) |
Get tstate (Tone State). | |
int | ast_dsp_getdigits (struct ast_dsp *dsp, char *buf, int max) |
Get pending DTMF/MF digits. | |
ast_dsp * | ast_dsp_new (void) |
ast_frame * | ast_dsp_process (struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf) |
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled. | |
void | ast_dsp_reset (struct ast_dsp *dsp) |
Reset total silence count. | |
void | ast_dsp_set_busy_compare (struct ast_dsp *dsp, int compare) |
Set if silence and noice lengths must be compared for busy. | |
void | ast_dsp_set_busy_count (struct ast_dsp *dsp, int cadences) |
Set number of required cadences for busy. | |
void | ast_dsp_set_busy_pattern (struct ast_dsp *dsp, int tonelength, int quietlength, int fuzzy) |
Set expected lengths of the busy tones. | |
int | ast_dsp_set_call_progress_zone (struct ast_dsp *dsp, char *zone) |
Set zone for doing progress detection. | |
void | ast_dsp_set_features (struct ast_dsp *dsp, int features) |
Select feature set. | |
void | ast_dsp_set_threshold (struct ast_dsp *dsp, int threshold) |
Set threshold value for silence. | |
int | ast_dsp_silence (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence) |
Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence. |
Definition in file dsp.h.
#define DSP_DIGITMODE_DTMF 0 |
Definition at line 31 of file dsp.h.
Referenced by ast_dsp_digitmode(), dahdi_hangup(), dahdi_new(), dahdi_setoption(), sip_new(), and ss_thread().
#define DSP_DIGITMODE_MF 1 |
Definition at line 32 of file dsp.h.
Referenced by __ast_dsp_digitdetect(), ast_dsp_digitmode(), ast_dsp_digitreset(), ast_dsp_getdigits(), ast_dsp_process(), and ss_thread().
#define DSP_DIGITMODE_MUTECONF (1 << 9) |
Definition at line 35 of file dsp.h.
Referenced by ast_dsp_digitmode(), ast_dsp_process(), and dahdi_setoption().
#define DSP_DIGITMODE_MUTEMAX (1 << 10) |
Definition at line 36 of file dsp.h.
Referenced by ast_dsp_digitmode(), ast_dsp_process(), and dahdi_setoption().
#define DSP_DIGITMODE_NOQUELCH (1 << 8) |
#define DSP_DIGITMODE_RELAXDTMF (1 << 11) |
Definition at line 37 of file dsp.h.
Referenced by __ast_dsp_digitdetect(), dahdi_setoption(), process_dahdi(), and sip_new().
#define DSP_FEATURE_BUSY_DETECT (1 << 1) |
#define DSP_FEATURE_CALL_PROGRESS (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION) |
Definition at line 43 of file dsp.h.
Referenced by __ast_dsp_call_progress(), ast_dsp_process(), and dahdi_new().
#define DSP_FEATURE_DTMF_DETECT (1 << 3) |
Definition at line 28 of file dsp.h.
Referenced by __oh323_new(), ast_dsp_process(), dahdi_new(), disable_dtmf_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), read_config(), sip_dtmfmode(), and sip_new().
#define DSP_FEATURE_FAX_DETECT (1 << 4) |
Definition at line 29 of file dsp.h.
Referenced by __ast_dsp_digitdetect(), dahdi_new(), misdn_set_opt_exec(), and read_config().
#define DSP_FEATURE_SILENCE_SUPPRESS (1 << 0) |
#define DSP_PROGRESS_BUSY (1 << 18) |
#define DSP_PROGRESS_CONGESTION (1 << 19) |
#define DSP_PROGRESS_RINGING (1 << 17) |
#define DSP_PROGRESS_TALK (1 << 16) |
#define DSP_TONE_STATE_BUSY 4 |
#define DSP_TONE_STATE_DIALTONE 2 |
#define DSP_TONE_STATE_HUNGUP 8 |
#define DSP_TONE_STATE_RINGING 1 |
#define DSP_TONE_STATE_SILENCE 0 |
#define DSP_TONE_STATE_SPECIAL1 5 |
#define DSP_TONE_STATE_SPECIAL2 6 |
#define DSP_TONE_STATE_SPECIAL3 7 |
#define DSP_TONE_STATE_TALKING 3 |
int ast_dsp_busydetect | ( | struct ast_dsp * | dsp | ) |
Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been called.
Definition at line 1282 of file dsp.c.
References ast_log(), BUSY_MAX, BUSY_MIN, ast_dsp::busy_pattern_fuzzy, BUSY_PERCENT, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, ast_dsp::busycompare, ast_dsp::busycount, ast_dsp::busymaybe, ast_dsp::busytoneonly, DSP_HISTORY, ast_dsp::historicnoise, ast_dsp::historicsilence, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, and option_debug.
Referenced by ast_dsp_process().
01283 { 01284 int res = 0, x; 01285 int avgsilence = 0, hitsilence = 0; 01286 int avgtone = 0, hittone = 0; 01287 #ifdef DEBUG_DSP_BUSYDETECT 01288 char buf[16]; 01289 char silence_list[64]="", tone_list[64]=""; 01290 #endif 01291 01292 if (!dsp->busymaybe) 01293 return res; 01294 dsp->busymaybe = 0; 01295 01296 for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) { 01297 avgsilence += dsp->historicsilence[x]; 01298 avgtone += dsp->historicnoise[x]; 01299 } 01300 avgsilence /= dsp->busycount; 01301 avgtone /= dsp->busycount; 01302 #ifdef DEBUG_DSP_BUSYDETECT 01303 sprintf(silence_list,"Silences: "); 01304 sprintf(tone_list,"Tones: "); 01305 #endif 01306 for (x=DSP_HISTORY - dsp->busycount; x<DSP_HISTORY; x++) { 01307 #ifdef DEBUG_DSP_BUSYDETECT 01308 snprintf(buf, sizeof(buf), "%5d ", dsp->historicsilence[x]); 01309 strcat(silence_list, buf); 01310 snprintf(buf, sizeof(buf), "%5d ", dsp->historicnoise[x]); 01311 strcat(tone_list, buf); 01312 #endif 01313 if (!dsp->busytoneonly) { 01314 if (avgsilence > dsp->historicsilence[x]) { 01315 if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x]) 01316 hitsilence++; 01317 } else { 01318 if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x]) 01319 hitsilence++; 01320 } 01321 } 01322 if (avgtone > dsp->historicnoise[x]) { 01323 if (avgtone - (avgtone*BUSY_PERCENT/100) <= dsp->historicnoise[x]) 01324 hittone++; 01325 } else { 01326 if (avgtone + (avgtone*BUSY_PERCENT/100) >= dsp->historicnoise[x]) 01327 hittone++; 01328 } 01329 } 01330 #ifdef DEBUG_DSP_BUSYDETECT 01331 fprintf(stderr, "BUSY DETECTOR\n"); 01332 fprintf(stderr, "%s\n", tone_list); 01333 fprintf(stderr, "%s\n", silence_list) 01334 #endif 01335 if ((dsp->busytoneonly || 01336 (hitsilence >= dsp->busycount - 1 && avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) && 01337 (hittone >= dsp->busycount - 1 && avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) { 01338 if (dsp->busycompare) { 01339 if (dsp->busytoneonly) { 01340 res = 1; 01341 ast_log(LOG_ERROR, "You can't use busytoneonly together with busycompare"); 01342 } else { 01343 if (avgtone > avgsilence) { 01344 if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) 01345 res = 1; 01346 } else { 01347 if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) 01348 res = 1; 01349 } 01350 } 01351 } else { 01352 res = 1; 01353 } 01354 } 01355 /* If we know the expected busy tone length, check we are in the range */ 01356 if (res && (dsp->busy_tonelength > 0)) { 01357 if (abs(avgtone - dsp->busy_tonelength) > (dsp->busy_tonelength*dsp->busy_pattern_fuzzy/100)) { 01358 if(option_debug) { 01359 ast_log(LOG_DEBUG, "busy detector: avgtone of %d not close enough to desired %d\n", avgtone, dsp->busy_tonelength); 01360 } 01361 res = 0; 01362 } 01363 } 01364 /* If we know the expected busy tone silent-period length, check we are in the range */ 01365 if (res && (!dsp->busytoneonly) && (dsp->busy_quietlength > 0)) { 01366 if (abs(avgsilence - dsp->busy_quietlength) > (dsp->busy_quietlength*dsp->busy_pattern_fuzzy/100)) { 01367 if(option_debug) { 01368 ast_log(LOG_DEBUG, "busy detector: avgsilence of %d not close enough to desired %d\n", avgsilence, dsp->busy_quietlength); 01369 } 01370 res = 0; 01371 } 01372 } 01373 if (res && option_debug) 01374 ast_log(LOG_NOTICE, "Detected busy sequence, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01375 return res; 01376 }
Scans for progress indication in audio.
Definition at line 1211 of file dsp.c.
References __ast_dsp_call_progress(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, LOG_WARNING, and ast_frame::subclass.
01212 { 01213 if (inf->frametype != AST_FRAME_VOICE) { 01214 ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n"); 01215 return 0; 01216 } 01217 if (inf->subclass != AST_FORMAT_SLINEAR) { 01218 ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n"); 01219 return 0; 01220 } 01221 return __ast_dsp_call_progress(dsp, inf->data, inf->datalen / 2); 01222 }
Return non-zero if DTMF hit was found.
Definition at line 1010 of file dsp.c.
References __ast_dsp_digitdetect(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, s, and ast_frame::subclass.
01011 { 01012 short *s; 01013 int len; 01014 int ign=0; 01015 01016 if (inf->frametype != AST_FRAME_VOICE) { 01017 ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n"); 01018 return 0; 01019 } 01020 if (inf->subclass != AST_FORMAT_SLINEAR) { 01021 ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n"); 01022 return 0; 01023 } 01024 s = inf->data; 01025 len = inf->datalen / 2; 01026 return __ast_dsp_digitdetect(dsp, s, len, &ign); 01027 }
int ast_dsp_digitmode | ( | struct ast_dsp * | dsp, | |
int | digitmode | |||
) |
Set digit mode.
Definition at line 1789 of file dsp.c.
References ast_dtmf_detect_init(), ast_mf_detect_init(), ast_dsp::digitmode, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_DIGITMODE_MUTECONF, DSP_DIGITMODE_MUTEMAX, ast_dsp::dtmf, ast_dsp::mf, and ast_dsp::td.
Referenced by dahdi_hangup(), dahdi_new(), dahdi_setoption(), mgcp_new(), sip_new(), and ss_thread().
01790 { 01791 int new; 01792 int old; 01793 01794 old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01795 new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01796 if (old != new) { 01797 /* Must initialize structures if switching from MF to DTMF or vice-versa */ 01798 if (new & DSP_DIGITMODE_MF) 01799 ast_mf_detect_init(&dsp->td.mf); 01800 else 01801 ast_dtmf_detect_init(&dsp->td.dtmf); 01802 } 01803 dsp->digitmode = digitmode; 01804 return 0; 01805 }
void ast_dsp_digitreset | ( | struct ast_dsp * | dsp | ) |
Reset DTMF detector.
Definition at line 1726 of file dsp.c.
References dtmf_detect_state_t::col_out, dtmf_detect_state_t::current_digits, mf_detect_state_t::current_digits, dtmf_detect_state_t::current_sample, mf_detect_state_t::current_sample, ast_dsp::digitmode, dtmf_detect_state_t::digits, mf_detect_state_t::digits, DSP_DIGITMODE_MF, ast_dsp::dtmf, dtmf_detect_state_t::energy, dtmf_detect_state_t::fax_tone, goertzel_reset(), mf_detect_state_t::hits, dtmf_detect_state_t::lasthit, ast_dsp::mf, dtmf_detect_state_t::mhit, mf_detect_state_t::mhit, dtmf_detect_state_t::row_out, ast_dsp::td, ast_dsp::thinkdigit, and mf_detect_state_t::tone_out.
Referenced by ss_thread().
01727 { 01728 int i; 01729 01730 dsp->thinkdigit = 0; 01731 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01732 memset(dsp->td.mf.digits, 0, sizeof(dsp->td.mf.digits)); 01733 dsp->td.mf.current_digits = 0; 01734 /* Reinitialise the detector for the next block */ 01735 for (i = 0; i < 6; i++) { 01736 goertzel_reset(&dsp->td.mf.tone_out[i]); 01737 #ifdef OLD_DSP_ROUTINES 01738 goertzel_reset(&dsp->td.mf.tone_out2nd[i]); 01739 #endif 01740 } 01741 #ifdef OLD_DSP_ROUTINES 01742 dsp->td.mf.energy = 0.0; 01743 dsp->td.mf.hit1 = dsp->td.mf.hit2 = dsp->td.mf.hit3 = dsp->td.mf.hit4 = dsp->td.mf.mhit = 0; 01744 #else 01745 dsp->td.mf.hits[4] = dsp->td.mf.hits[3] = dsp->td.mf.hits[2] = dsp->td.mf.hits[1] = dsp->td.mf.hits[0] = dsp->td.mf.mhit = 0; 01746 #endif 01747 dsp->td.mf.current_sample = 0; 01748 } else { 01749 memset(dsp->td.dtmf.digits, 0, sizeof(dsp->td.dtmf.digits)); 01750 dsp->td.dtmf.current_digits = 0; 01751 /* Reinitialise the detector for the next block */ 01752 for (i = 0; i < 4; i++) { 01753 goertzel_reset(&dsp->td.dtmf.row_out[i]); 01754 goertzel_reset(&dsp->td.dtmf.col_out[i]); 01755 #ifdef OLD_DSP_ROUTINES 01756 goertzel_reset(&dsp->td.dtmf.row_out2nd[i]); 01757 goertzel_reset(&dsp->td.dtmf.col_out2nd[i]); 01758 #endif 01759 } 01760 #ifdef FAX_DETECT 01761 goertzel_reset (&dsp->td.dtmf.fax_tone); 01762 #endif 01763 #ifdef OLD_DSP_ROUTINES 01764 #ifdef FAX_DETECT 01765 goertzel_reset (&dsp->td.dtmf.fax_tone2nd); 01766 #endif 01767 dsp->td.dtmf.hit1 = dsp->td.dtmf.hit2 = dsp->td.dtmf.hit3 = dsp->td.dtmf.hit4 = dsp->td.dtmf.mhit = 0; 01768 #else 01769 dsp->td.dtmf.lasthit = dsp->td.dtmf.mhit = 0; 01770 #endif 01771 dsp->td.dtmf.energy = 0.0; 01772 dsp->td.dtmf.current_sample = 0; 01773 } 01774 }
void ast_dsp_free | ( | struct ast_dsp * | dsp | ) |
Definition at line 1684 of file dsp.c.
References free.
Referenced by __ast_play_and_record(), __oh323_destroy(), background_detect_exec(), cl_dequeue_chan(), cleanup_connection(), dahdi_hangup(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_hangup(), sip_dtmfmode(), sip_hangup(), and ss_thread().
01685 { 01686 free(dsp); 01687 }
int ast_dsp_get_tcount | ( | struct ast_dsp * | dsp | ) |
Get tcount (Threshold counter).
Definition at line 1826 of file dsp.c.
References ast_dsp::tcount.
01827 { 01828 return dsp->tcount; 01829 }
int ast_dsp_get_tstate | ( | struct ast_dsp * | dsp | ) |
Get tstate (Tone State).
Definition at line 1821 of file dsp.c.
References ast_dsp::tstate.
01822 { 01823 return dsp->tstate; 01824 }
int ast_dsp_getdigits | ( | struct ast_dsp * | dsp, | |
char * | buf, | |||
int | max | |||
) |
Get pending DTMF/MF digits.
Definition at line 1049 of file dsp.c.
References dtmf_detect_state_t::current_digits, mf_detect_state_t::current_digits, ast_dsp::digitmode, dtmf_detect_state_t::digits, mf_detect_state_t::digits, DSP_DIGITMODE_MF, ast_dsp::dtmf, ast_dsp::mf, and ast_dsp::td.
01050 { 01051 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01052 if (max > dsp->td.mf.current_digits) 01053 max = dsp->td.mf.current_digits; 01054 if (max > 0) { 01055 memcpy(buf, dsp->td.mf.digits, max); 01056 memmove(dsp->td.mf.digits, dsp->td.mf.digits + max, dsp->td.mf.current_digits - max); 01057 dsp->td.mf.current_digits -= max; 01058 } 01059 buf[max] = '\0'; 01060 return max; 01061 } else { 01062 if (max > dsp->td.dtmf.current_digits) 01063 max = dsp->td.dtmf.current_digits; 01064 if (max > 0) { 01065 memcpy (buf, dsp->td.dtmf.digits, max); 01066 memmove (dsp->td.dtmf.digits, dsp->td.dtmf.digits + max, dsp->td.dtmf.current_digits - max); 01067 dsp->td.dtmf.current_digits -= max; 01068 } 01069 buf[max] = '\0'; 01070 return max; 01071 } 01072 }
struct ast_dsp* ast_dsp_new | ( | void | ) |
Definition at line 1649 of file dsp.c.
References ast_calloc, ast_dsp_prog_reset(), ast_dtmf_detect_init(), BUSY_PAT_PERCENT, DEFAULT_THRESHOLD, DSP_FEATURE_SILENCE_SUPPRESS, DSP_HISTORY, and ast_dsp::threshold.
Referenced by __ast_play_and_record(), __oh323_new(), background_detect_exec(), conf_run(), dahdi_new(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_new(), misdn_set_opt_exec(), read_config(), sip_dtmfmode(), and sip_new().
01650 { 01651 struct ast_dsp *dsp; 01652 01653 if ((dsp = ast_calloc(1, sizeof(*dsp)))) { 01654 dsp->threshold = DEFAULT_THRESHOLD; 01655 dsp->features = DSP_FEATURE_SILENCE_SUPPRESS; 01656 dsp->busycount = DSP_HISTORY; 01657 dsp->busy_pattern_fuzzy = BUSY_PAT_PERCENT; 01658 #ifdef BUSYDETECT_TONEONLY 01659 dsp->busytoneonly = 1; 01660 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01661 #error "You can't use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE"); 01662 #endif 01663 #else 01664 dsp->busytoneonly = 0; 01665 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01666 dsp->busycompare = 1; 01667 #else 01668 dsp->busycompare = 0; 01669 #endif 01670 #endif 01671 /* Initialize DTMF detector */ 01672 ast_dtmf_detect_init(&dsp->td.dtmf); 01673 /* Initialize initial DSP progress detect parameters */ 01674 ast_dsp_prog_reset(dsp); 01675 } 01676 return dsp; 01677 }
struct ast_frame* ast_dsp_process | ( | struct ast_channel * | chan, | |
struct ast_dsp * | dsp, | |||
struct ast_frame * | inf | |||
) |
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled.
Definition at line 1442 of file dsp.c.
References __ast_dsp_call_progress(), __ast_dsp_digitdetect(), __ast_dsp_silence(), ast_channel::_softhangup, AST_ALAW, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_dsp_busydetect(), AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), ast_getformatname(), ast_log(), AST_MULAW, ast_queue_frame(), AST_SOFTHANGUP_DEV, dtmf_detect_state_t::current_digits, mf_detect_state_t::current_digits, ast_frame::data, ast_frame::datalen, ast_dsp::digitmode, dtmf_detect_state_t::digits, mf_detect_state_t::digits, DSP_DIGITMODE_MF, DSP_DIGITMODE_MUTECONF, DSP_DIGITMODE_MUTEMAX, DSP_FEATURE_BUSY_DETECT, DSP_FEATURE_CALL_PROGRESS, DSP_FEATURE_DTMF_DETECT, DSP_FEATURE_SILENCE_SUPPRESS, ast_dsp::dtmf, ast_dsp::f, ast_dsp::features, FIX_INF, ast_frame::frametype, len(), LOG_WARNING, ast_dsp::mf, silence, ast_frame::src, ast_frame::subclass, ast_dsp::td, and ast_dsp::thinkdigit.
Referenced by dahdi_read(), mgcp_rtp_read(), oh323_rtp_read(), process_ast_dsp(), and sip_rtp_read().
01443 { 01444 int silence; 01445 int res; 01446 int digit; 01447 int x; 01448 short *shortdata; 01449 unsigned char *odata; 01450 int len; 01451 int writeback = 0; 01452 01453 #define FIX_INF(inf) do { \ 01454 if (writeback) { \ 01455 switch(inf->subclass) { \ 01456 case AST_FORMAT_SLINEAR: \ 01457 break; \ 01458 case AST_FORMAT_ULAW: \ 01459 for (x=0;x<len;x++) \ 01460 odata[x] = AST_LIN2MU((unsigned short)shortdata[x]); \ 01461 break; \ 01462 case AST_FORMAT_ALAW: \ 01463 for (x=0;x<len;x++) \ 01464 odata[x] = AST_LIN2A((unsigned short)shortdata[x]); \ 01465 break; \ 01466 } \ 01467 } \ 01468 } while(0) 01469 01470 if (!af) 01471 return NULL; 01472 if (af->frametype != AST_FRAME_VOICE) 01473 return af; 01474 odata = af->data; 01475 len = af->datalen; 01476 /* Make sure we have short data */ 01477 switch(af->subclass) { 01478 case AST_FORMAT_SLINEAR: 01479 shortdata = af->data; 01480 len = af->datalen / 2; 01481 break; 01482 case AST_FORMAT_ULAW: 01483 shortdata = alloca(af->datalen * 2); 01484 for (x = 0;x < len; x++) 01485 shortdata[x] = AST_MULAW(odata[x]); 01486 break; 01487 case AST_FORMAT_ALAW: 01488 shortdata = alloca(af->datalen * 2); 01489 for (x = 0; x < len; x++) 01490 shortdata[x] = AST_ALAW(odata[x]); 01491 break; 01492 default: 01493 ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass)); 01494 return af; 01495 } 01496 silence = __ast_dsp_silence(dsp, shortdata, len, NULL); 01497 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) { 01498 memset(&dsp->f, 0, sizeof(dsp->f)); 01499 dsp->f.frametype = AST_FRAME_NULL; 01500 ast_frfree(af); 01501 return ast_frisolate(&dsp->f); 01502 } 01503 if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) { 01504 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01505 memset(&dsp->f, 0, sizeof(dsp->f)); 01506 dsp->f.frametype = AST_FRAME_CONTROL; 01507 dsp->f.subclass = AST_CONTROL_BUSY; 01508 ast_frfree(af); 01509 return ast_frisolate(&dsp->f); 01510 } 01511 if ((dsp->features & DSP_FEATURE_DTMF_DETECT)) { 01512 digit = __ast_dsp_digitdetect(dsp, shortdata, len, &writeback); 01513 #if 0 01514 if (digit) 01515 printf("Performing digit detection returned %d, digitmode is %d\n", digit, dsp->digitmode); 01516 #endif 01517 if (dsp->digitmode & (DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX)) { 01518 if (!dsp->thinkdigit) { 01519 if (digit) { 01520 /* Looks like we might have something. 01521 * Request a conference mute for the moment */ 01522 memset(&dsp->f, 0, sizeof(dsp->f)); 01523 dsp->f.frametype = AST_FRAME_DTMF; 01524 dsp->f.subclass = 'm'; 01525 dsp->thinkdigit = 'x'; 01526 FIX_INF(af); 01527 if (chan) 01528 ast_queue_frame(chan, af); 01529 ast_frfree(af); 01530 return ast_frisolate(&dsp->f); 01531 } 01532 } else { 01533 if (digit) { 01534 /* Thought we saw one last time. Pretty sure we really have now */ 01535 if ((dsp->thinkdigit != 'x') && (dsp->thinkdigit != digit)) { 01536 /* If we found a digit, and we're changing digits, go 01537 ahead and send this one, but DON'T stop confmute because 01538 we're detecting something else, too... */ 01539 memset(&dsp->f, 0, sizeof(dsp->f)); 01540 dsp->f.frametype = AST_FRAME_DTMF_END; 01541 dsp->f.subclass = dsp->thinkdigit; 01542 FIX_INF(af); 01543 if (chan) 01544 ast_queue_frame(chan, af); 01545 ast_frfree(af); 01546 } else { 01547 dsp->thinkdigit = digit; 01548 memset(&dsp->f, 0, sizeof(dsp->f)); 01549 dsp->f.frametype = AST_FRAME_DTMF_BEGIN; 01550 dsp->f.subclass = dsp->thinkdigit; 01551 FIX_INF(af); 01552 if (chan) 01553 ast_queue_frame(chan, af); 01554 ast_frfree(af); 01555 } 01556 return ast_frisolate(&dsp->f); 01557 } else { 01558 memset(&dsp->f, 0, sizeof(dsp->f)); 01559 if (dsp->thinkdigit != 'x') { 01560 /* If we found a digit, send it now */ 01561 dsp->f.frametype = AST_FRAME_DTMF_END; 01562 dsp->f.subclass = dsp->thinkdigit; 01563 dsp->thinkdigit = 0; 01564 } else { 01565 dsp->f.frametype = AST_FRAME_DTMF; 01566 dsp->f.subclass = 'u'; 01567 dsp->thinkdigit = 0; 01568 } 01569 FIX_INF(af); 01570 if (chan) 01571 ast_queue_frame(chan, af); 01572 ast_frfree(af); 01573 return ast_frisolate(&dsp->f); 01574 } 01575 } 01576 } else if (!digit) { 01577 /* Only check when there is *not* a hit... */ 01578 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01579 if (dsp->td.mf.current_digits) { 01580 memset(&dsp->f, 0, sizeof(dsp->f)); 01581 dsp->f.frametype = AST_FRAME_DTMF; 01582 dsp->f.subclass = dsp->td.mf.digits[0]; 01583 memmove(dsp->td.mf.digits, dsp->td.mf.digits + 1, dsp->td.mf.current_digits); 01584 dsp->td.mf.current_digits--; 01585 FIX_INF(af); 01586 if (chan) 01587 ast_queue_frame(chan, af); 01588 ast_frfree(af); 01589 return ast_frisolate(&dsp->f); 01590 } 01591 } else { 01592 if (dsp->td.dtmf.current_digits) { 01593 memset(&dsp->f, 0, sizeof(dsp->f)); 01594 dsp->f.frametype = AST_FRAME_DTMF_END; 01595 dsp->f.subclass = dsp->td.dtmf.digits[0]; 01596 memmove(dsp->td.dtmf.digits, dsp->td.dtmf.digits + 1, dsp->td.dtmf.current_digits); 01597 dsp->td.dtmf.current_digits--; 01598 FIX_INF(af); 01599 if (chan) 01600 ast_queue_frame(chan, af); 01601 ast_frfree(af); 01602 return ast_frisolate(&dsp->f); 01603 } 01604 } 01605 } 01606 } 01607 if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) { 01608 res = __ast_dsp_call_progress(dsp, shortdata, len); 01609 if (res) { 01610 switch(res) { 01611 case AST_CONTROL_ANSWER: 01612 case AST_CONTROL_BUSY: 01613 case AST_CONTROL_RINGING: 01614 case AST_CONTROL_CONGESTION: 01615 case AST_CONTROL_HANGUP: 01616 memset(&dsp->f, 0, sizeof(dsp->f)); 01617 dsp->f.frametype = AST_FRAME_CONTROL; 01618 dsp->f.subclass = res; 01619 dsp->f.src = "dsp_progress"; 01620 if (chan) 01621 ast_queue_frame(chan, &dsp->f); 01622 break; 01623 default: 01624 ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); 01625 } 01626 } 01627 } 01628 FIX_INF(af); 01629 return af; 01630 }
void ast_dsp_reset | ( | struct ast_dsp * | dsp | ) |
Reset total silence count.
Definition at line 1776 of file dsp.c.
References ast_dsp::freqs, ast_dsp::gsamps, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_dsp::ringtimeout, ast_dsp::totalsilence, goertzel_state_t::v2, and goertzel_state_t::v3.
01777 { 01778 int x; 01779 01780 dsp->totalsilence = 0; 01781 dsp->gsamps = 0; 01782 for (x=0;x<4;x++) 01783 dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0; 01784 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01785 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01786 dsp->ringtimeout= 0; 01787 }
void ast_dsp_set_busy_compare | ( | struct ast_dsp * | dsp, | |
int | compare | |||
) |
Set if silence and noice lengths must be compared for busy.
Definition at line 1706 of file dsp.c.
References ast_dsp::busycompare.
Referenced by dahdi_new().
01707 { 01708 if (compare > 0) 01709 dsp->busycompare = 1; 01710 else 01711 dsp->busycompare = 0; 01712 }
void ast_dsp_set_busy_count | ( | struct ast_dsp * | dsp, | |
int | cadences | |||
) |
Set number of required cadences for busy.
Definition at line 1697 of file dsp.c.
References ast_dsp::busycount, and DSP_HISTORY.
Referenced by dahdi_new().
01698 { 01699 if (cadences < 4) 01700 cadences = 4; 01701 if (cadences > DSP_HISTORY) 01702 cadences = DSP_HISTORY; 01703 dsp->busycount = cadences; 01704 }
void ast_dsp_set_busy_pattern | ( | struct ast_dsp * | dsp, | |
int | tonelength, | |||
int | quietlength, | |||
int | fuzzy | |||
) |
Set expected lengths of the busy tones.
Definition at line 1714 of file dsp.c.
References ast_log(), ast_dsp::busy_pattern_fuzzy, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, ast_dsp::busytoneonly, and LOG_DEBUG.
Referenced by dahdi_new().
01715 { 01716 dsp->busy_tonelength = tonelength; 01717 if (quietlength > 0) 01718 dsp->busy_quietlength = quietlength; 01719 else 01720 dsp->busytoneonly = 1; 01721 ast_log(LOG_DEBUG, "dsp busy pattern set to %d,%d\n", tonelength, quietlength); 01722 if( fuzzy > 0 && fuzzy < 50 ) 01723 dsp->busy_pattern_fuzzy = fuzzy; 01724 }
int ast_dsp_set_call_progress_zone | ( | struct ast_dsp * | dsp, | |
char * | zone | |||
) |
Set zone for doing progress detection.
Definition at line 1807 of file dsp.c.
References aliases, ast_dsp_prog_reset(), name, and ast_dsp::progmode.
Referenced by dahdi_new().
01808 { 01809 int x; 01810 01811 for (x=0;x<sizeof(aliases) / sizeof(aliases[0]);x++) { 01812 if (!strcasecmp(aliases[x].name, zone)) { 01813 dsp->progmode = aliases[x].mode; 01814 ast_dsp_prog_reset(dsp); 01815 return 0; 01816 } 01817 } 01818 return -1; 01819 }
void ast_dsp_set_features | ( | struct ast_dsp * | dsp, | |
int | features | |||
) |
Select feature set.
Definition at line 1679 of file dsp.c.
References ast_dsp::features.
Referenced by __oh323_new(), dahdi_new(), disable_dtmf_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), read_config(), sip_dtmfmode(), and sip_new().
void ast_dsp_set_threshold | ( | struct ast_dsp * | dsp, | |
int | threshold | |||
) |
Set threshold value for silence.
Definition at line 1689 of file dsp.c.
References ast_dsp::threshold.
Referenced by __ast_play_and_record(), dahdi_new(), do_waiting(), handle_recordfile(), and isAnsweringMachine().
01690 { 01691 if (threshold < 256) 01692 dsp->threshold = 256; 01693 else 01694 dsp->threshold = threshold; 01695 }
Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence.
Definition at line 1424 of file dsp.c.
References __ast_dsp_silence(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), f, len(), LOG_WARNING, and s.
Referenced by __ast_play_and_record(), background_detect_exec(), conf_run(), do_waiting(), handle_recordfile(), and isAnsweringMachine().
01425 { 01426 short *s; 01427 int len; 01428 01429 if (f->frametype != AST_FRAME_VOICE) { 01430 ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n"); 01431 return 0; 01432 } 01433 if (f->subclass != AST_FORMAT_SLINEAR) { 01434 ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n"); 01435 return 0; 01436 } 01437 s = f->data; 01438 len = f->datalen/2; 01439 return __ast_dsp_silence(dsp, s, len, totalsilence); 01440 }