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_frame_freed (struct ast_frame *fr) |
Hint that a frame from a dsp was freed. | |
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 1807 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().
01808 { 01809 int new; 01810 int old; 01811 01812 old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01813 new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01814 if (old != new) { 01815 /* Must initialize structures if switching from MF to DTMF or vice-versa */ 01816 if (new & DSP_DIGITMODE_MF) 01817 ast_mf_detect_init(&dsp->td.mf); 01818 else 01819 ast_dtmf_detect_init(&dsp->td.dtmf); 01820 } 01821 dsp->digitmode = digitmode; 01822 return 0; 01823 }
void ast_dsp_digitreset | ( | struct ast_dsp * | dsp | ) |
Reset DTMF detector.
Definition at line 1744 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().
01745 { 01746 int i; 01747 01748 dsp->thinkdigit = 0; 01749 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01750 memset(dsp->td.mf.digits, 0, sizeof(dsp->td.mf.digits)); 01751 dsp->td.mf.current_digits = 0; 01752 /* Reinitialise the detector for the next block */ 01753 for (i = 0; i < 6; i++) { 01754 goertzel_reset(&dsp->td.mf.tone_out[i]); 01755 #ifdef OLD_DSP_ROUTINES 01756 goertzel_reset(&dsp->td.mf.tone_out2nd[i]); 01757 #endif 01758 } 01759 #ifdef OLD_DSP_ROUTINES 01760 dsp->td.mf.energy = 0.0; 01761 dsp->td.mf.hit1 = dsp->td.mf.hit2 = dsp->td.mf.hit3 = dsp->td.mf.hit4 = dsp->td.mf.mhit = 0; 01762 #else 01763 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; 01764 #endif 01765 dsp->td.mf.current_sample = 0; 01766 } else { 01767 memset(dsp->td.dtmf.digits, 0, sizeof(dsp->td.dtmf.digits)); 01768 dsp->td.dtmf.current_digits = 0; 01769 /* Reinitialise the detector for the next block */ 01770 for (i = 0; i < 4; i++) { 01771 goertzel_reset(&dsp->td.dtmf.row_out[i]); 01772 goertzel_reset(&dsp->td.dtmf.col_out[i]); 01773 #ifdef OLD_DSP_ROUTINES 01774 goertzel_reset(&dsp->td.dtmf.row_out2nd[i]); 01775 goertzel_reset(&dsp->td.dtmf.col_out2nd[i]); 01776 #endif 01777 } 01778 #ifdef FAX_DETECT 01779 goertzel_reset (&dsp->td.dtmf.fax_tone); 01780 #endif 01781 #ifdef OLD_DSP_ROUTINES 01782 #ifdef FAX_DETECT 01783 goertzel_reset (&dsp->td.dtmf.fax_tone2nd); 01784 #endif 01785 dsp->td.dtmf.hit1 = dsp->td.dtmf.hit2 = dsp->td.dtmf.hit3 = dsp->td.dtmf.hit4 = dsp->td.dtmf.mhit = 0; 01786 #else 01787 dsp->td.dtmf.lasthit = dsp->td.dtmf.mhit = 0; 01788 #endif 01789 dsp->td.dtmf.energy = 0.0; 01790 dsp->td.dtmf.current_sample = 0; 01791 } 01792 }
void ast_dsp_frame_freed | ( | struct ast_frame * | fr | ) |
Hint that a frame from a dsp was freed.
This is called from ast_frame_free if AST_FRFLAG_FROM_DSP is set. This occurs because it is possible for the dsp to be freed while someone still holds a reference to the frame that is in that dsp. This has been known to happen when the dsp on a Zap channel detects a busy signal. The channel is hung up, and the application that read the frame to begin with still has a reference to the frame.
Definition at line 1849 of file dsp.c.
References ast_clear_flag, ast_dsp_free(), AST_FRFLAG_FROM_DSP, f, and ast_dsp::freqcount.
Referenced by ast_frame_free().
01850 { 01851 struct ast_dsp *dsp; 01852 01853 ast_clear_flag(fr, AST_FRFLAG_FROM_DSP); 01854 01855 dsp = (struct ast_dsp *) (((char *) fr) - offsetof(struct ast_dsp, f)); 01856 01857 if (dsp->freqcount != -1) 01858 return; 01859 01860 ast_dsp_free(dsp); 01861 }
void ast_dsp_free | ( | struct ast_dsp * | dsp | ) |
Definition at line 1691 of file dsp.c.
References AST_FRFLAG_FROM_DSP, ast_test_flag, ast_dsp::f, free, and ast_dsp::freqcount.
Referenced by __ast_play_and_record(), __oh323_destroy(), ast_dsp_frame_freed(), background_detect_exec(), cl_dequeue_chan(), cleanup_connection(), dahdi_hangup(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_hangup(), sip_dtmfmode(), sip_hangup(), and ss_thread().
01692 { 01693 if (ast_test_flag(&dsp->f, AST_FRFLAG_FROM_DSP)) { 01694 /* If this flag is still set, that means that the dsp's destruction 01695 * been torn down, while we still have a frame out there being used. 01696 * When ast_frfree() gets called on that frame, this ast_trans_pvt 01697 * will get destroyed, too. */ 01698 01699 /* Set the magic hint that this has been requested to be destroyed. */ 01700 dsp->freqcount = -1; 01701 01702 return; 01703 } 01704 free(dsp); 01705 }
int ast_dsp_get_tcount | ( | struct ast_dsp * | dsp | ) |
Get tcount (Threshold counter).
Definition at line 1844 of file dsp.c.
References ast_dsp::tcount.
01845 { 01846 return dsp->tcount; 01847 }
int ast_dsp_get_tstate | ( | struct ast_dsp * | dsp | ) |
Get tstate (Tone State).
Definition at line 1839 of file dsp.c.
References ast_dsp::tstate.
01840 { 01841 return dsp->tstate; 01842 }
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 1656 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().
01657 { 01658 struct ast_dsp *dsp; 01659 01660 if ((dsp = ast_calloc(1, sizeof(*dsp)))) { 01661 dsp->threshold = DEFAULT_THRESHOLD; 01662 dsp->features = DSP_FEATURE_SILENCE_SUPPRESS; 01663 dsp->busycount = DSP_HISTORY; 01664 dsp->busy_pattern_fuzzy = BUSY_PAT_PERCENT; 01665 #ifdef BUSYDETECT_TONEONLY 01666 dsp->busytoneonly = 1; 01667 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01668 #error "You can't use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE"); 01669 #endif 01670 #else 01671 dsp->busytoneonly = 0; 01672 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01673 dsp->busycompare = 1; 01674 #else 01675 dsp->busycompare = 0; 01676 #endif 01677 #endif 01678 /* Initialize DTMF detector */ 01679 ast_dtmf_detect_init(&dsp->td.dtmf); 01680 /* Initialize initial DSP progress detect parameters */ 01681 ast_dsp_prog_reset(dsp); 01682 } 01683 return dsp; 01684 }
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_FRFLAG_FROM_DSP, ast_frfree, ast_getformatname(), ast_log(), AST_MULAW, ast_queue_frame(), ast_set_flag, 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 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01502 return &dsp->f; 01503 } 01504 if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) { 01505 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01506 memset(&dsp->f, 0, sizeof(dsp->f)); 01507 dsp->f.frametype = AST_FRAME_CONTROL; 01508 dsp->f.subclass = AST_CONTROL_BUSY; 01509 ast_frfree(af); 01510 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01511 return &dsp->f; 01512 } 01513 if ((dsp->features & DSP_FEATURE_DTMF_DETECT)) { 01514 digit = __ast_dsp_digitdetect(dsp, shortdata, len, &writeback); 01515 #if 0 01516 if (digit) 01517 printf("Performing digit detection returned %d, digitmode is %d\n", digit, dsp->digitmode); 01518 #endif 01519 if (dsp->digitmode & (DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX)) { 01520 if (!dsp->thinkdigit) { 01521 if (digit) { 01522 /* Looks like we might have something. 01523 * Request a conference mute for the moment */ 01524 memset(&dsp->f, 0, sizeof(dsp->f)); 01525 dsp->f.frametype = AST_FRAME_DTMF; 01526 dsp->f.subclass = 'm'; 01527 dsp->thinkdigit = 'x'; 01528 FIX_INF(af); 01529 if (chan) 01530 ast_queue_frame(chan, af); 01531 ast_frfree(af); 01532 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01533 return &dsp->f; 01534 } 01535 } else { 01536 if (digit) { 01537 /* Thought we saw one last time. Pretty sure we really have now */ 01538 if ((dsp->thinkdigit != 'x') && (dsp->thinkdigit != digit)) { 01539 /* If we found a digit, and we're changing digits, go 01540 ahead and send this one, but DON'T stop confmute because 01541 we're detecting something else, too... */ 01542 memset(&dsp->f, 0, sizeof(dsp->f)); 01543 dsp->f.frametype = AST_FRAME_DTMF_END; 01544 dsp->f.subclass = dsp->thinkdigit; 01545 FIX_INF(af); 01546 if (chan) 01547 ast_queue_frame(chan, af); 01548 ast_frfree(af); 01549 } else { 01550 dsp->thinkdigit = digit; 01551 memset(&dsp->f, 0, sizeof(dsp->f)); 01552 dsp->f.frametype = AST_FRAME_DTMF_BEGIN; 01553 dsp->f.subclass = dsp->thinkdigit; 01554 FIX_INF(af); 01555 if (chan) 01556 ast_queue_frame(chan, af); 01557 ast_frfree(af); 01558 } 01559 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01560 return &dsp->f; 01561 } else { 01562 memset(&dsp->f, 0, sizeof(dsp->f)); 01563 if (dsp->thinkdigit != 'x') { 01564 /* If we found a digit, send it now */ 01565 dsp->f.frametype = AST_FRAME_DTMF_END; 01566 dsp->f.subclass = dsp->thinkdigit; 01567 dsp->thinkdigit = 0; 01568 } else { 01569 dsp->f.frametype = AST_FRAME_DTMF; 01570 dsp->f.subclass = 'u'; 01571 dsp->thinkdigit = 0; 01572 } 01573 FIX_INF(af); 01574 if (chan) 01575 ast_queue_frame(chan, af); 01576 ast_frfree(af); 01577 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01578 return &dsp->f; 01579 } 01580 } 01581 } else if (!digit) { 01582 /* Only check when there is *not* a hit... */ 01583 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01584 if (dsp->td.mf.current_digits) { 01585 memset(&dsp->f, 0, sizeof(dsp->f)); 01586 dsp->f.frametype = AST_FRAME_DTMF; 01587 dsp->f.subclass = dsp->td.mf.digits[0]; 01588 memmove(dsp->td.mf.digits, dsp->td.mf.digits + 1, dsp->td.mf.current_digits); 01589 dsp->td.mf.current_digits--; 01590 FIX_INF(af); 01591 if (chan) 01592 ast_queue_frame(chan, af); 01593 ast_frfree(af); 01594 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01595 return &dsp->f; 01596 } 01597 } else { 01598 if (dsp->td.dtmf.current_digits) { 01599 memset(&dsp->f, 0, sizeof(dsp->f)); 01600 dsp->f.frametype = AST_FRAME_DTMF_END; 01601 dsp->f.subclass = dsp->td.dtmf.digits[0]; 01602 memmove(dsp->td.dtmf.digits, dsp->td.dtmf.digits + 1, dsp->td.dtmf.current_digits); 01603 dsp->td.dtmf.current_digits--; 01604 FIX_INF(af); 01605 if (chan) 01606 ast_queue_frame(chan, af); 01607 ast_frfree(af); 01608 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01609 return &dsp->f; 01610 } 01611 } 01612 } 01613 } 01614 if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) { 01615 res = __ast_dsp_call_progress(dsp, shortdata, len); 01616 if (res) { 01617 switch(res) { 01618 case AST_CONTROL_ANSWER: 01619 case AST_CONTROL_BUSY: 01620 case AST_CONTROL_RINGING: 01621 case AST_CONTROL_CONGESTION: 01622 case AST_CONTROL_HANGUP: 01623 memset(&dsp->f, 0, sizeof(dsp->f)); 01624 dsp->f.frametype = AST_FRAME_CONTROL; 01625 dsp->f.subclass = res; 01626 dsp->f.src = "dsp_progress"; 01627 if (chan) 01628 ast_queue_frame(chan, &dsp->f); 01629 break; 01630 default: 01631 ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); 01632 } 01633 } 01634 } 01635 FIX_INF(af); 01636 return af; 01637 }
void ast_dsp_reset | ( | struct ast_dsp * | dsp | ) |
Reset total silence count.
Definition at line 1794 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.
01795 { 01796 int x; 01797 01798 dsp->totalsilence = 0; 01799 dsp->gsamps = 0; 01800 for (x=0;x<4;x++) 01801 dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0; 01802 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01803 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01804 dsp->ringtimeout= 0; 01805 }
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 1724 of file dsp.c.
References ast_dsp::busycompare.
Referenced by dahdi_new().
01725 { 01726 if (compare > 0) 01727 dsp->busycompare = 1; 01728 else 01729 dsp->busycompare = 0; 01730 }
void ast_dsp_set_busy_count | ( | struct ast_dsp * | dsp, | |
int | cadences | |||
) |
Set number of required cadences for busy.
Definition at line 1715 of file dsp.c.
References ast_dsp::busycount, and DSP_HISTORY.
Referenced by dahdi_new().
01716 { 01717 if (cadences < 4) 01718 cadences = 4; 01719 if (cadences > DSP_HISTORY) 01720 cadences = DSP_HISTORY; 01721 dsp->busycount = cadences; 01722 }
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 1732 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().
01733 { 01734 dsp->busy_tonelength = tonelength; 01735 if (quietlength > 0) 01736 dsp->busy_quietlength = quietlength; 01737 else 01738 dsp->busytoneonly = 1; 01739 ast_log(LOG_DEBUG, "dsp busy pattern set to %d,%d\n", tonelength, quietlength); 01740 if( fuzzy > 0 && fuzzy < 50 ) 01741 dsp->busy_pattern_fuzzy = fuzzy; 01742 }
int ast_dsp_set_call_progress_zone | ( | struct ast_dsp * | dsp, | |
char * | zone | |||
) |
Set zone for doing progress detection.
Definition at line 1825 of file dsp.c.
References aliases, ast_dsp_prog_reset(), name, and ast_dsp::progmode.
Referenced by dahdi_new().
01826 { 01827 int x; 01828 01829 for (x=0;x<sizeof(aliases) / sizeof(aliases[0]);x++) { 01830 if (!strcasecmp(aliases[x].name, zone)) { 01831 dsp->progmode = aliases[x].mode; 01832 ast_dsp_prog_reset(dsp); 01833 return 0; 01834 } 01835 } 01836 return -1; 01837 }
void ast_dsp_set_features | ( | struct ast_dsp * | dsp, | |
int | features | |||
) |
Select feature set.
Definition at line 1686 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 1707 of file dsp.c.
References ast_dsp::threshold.
Referenced by __ast_play_and_record(), dahdi_new(), do_waiting(), handle_recordfile(), and isAnsweringMachine().
01708 { 01709 if (threshold < 256) 01710 dsp->threshold = 256; 01711 else 01712 dsp->threshold = threshold; 01713 }
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 }