
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_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED) |
| #define | DSP_FAXMODE_DETECT_CED (1 << 1) |
| #define | DSP_FAXMODE_DETECT_CNG (1 << 0) |
| #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_DIGIT_DETECT (1 << 3) |
| #define | DSP_FEATURE_FAX_DETECT (1 << 4) |
| #define | DSP_FEATURE_SILENCE_SUPPRESS (1 << 0) |
| #define | DSP_FEATURE_WAITDIALTONE (1 << 20) |
| #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 |
Enumerations | |
| enum | threshold { THRESHOLD_SILENCE = 0, THRESHOLD_MAX = 1 } |
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. | |
| 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_threshold_from_settings (enum threshold which) |
| Get silence threshold from dsp.conf. | |
| 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. | |
| int | ast_dsp_init (void) |
| Load dsp settings from dsp.conf. | |
| struct ast_dsp * | ast_dsp_new (void) |
| int | ast_dsp_noise (struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise) |
| Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise. | |
| 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. | |
| int | ast_dsp_reload (void) |
| Reloads dsp settings from dsp.conf. | |
| void | ast_dsp_reset (struct ast_dsp *dsp) |
| Reset total silence count. | |
| 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) |
| Set expected lengths of the busy tone. | |
| int | ast_dsp_set_call_progress_zone (struct ast_dsp *dsp, char *zone) |
| Set zone for doing progress detection. | |
| int | ast_dsp_set_digitmode (struct ast_dsp *dsp, int digitmode) |
| Set digit mode. | |
| int | ast_dsp_set_faxmode (struct ast_dsp *dsp, int faxmode) |
| Set fax mode. | |
| 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. | |
| int | ast_dsp_was_muted (struct ast_dsp *dsp) |
| Returns true if DSP code was muting any fragment of the last processed frame. Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio. | |
Definition in file dsp.h.
| #define DSP_DIGITMODE_DTMF 0 |
Detect DTMF digits
Definition at line 31 of file dsp.h.
Referenced by ast_dsp_new(), ast_dsp_set_digitmode(), dahdi_hangup(), dahdi_new(), dahdi_setoption(), mkintf(), sip_new(), ss_thread(), and store_config().
| #define DSP_DIGITMODE_MF 1 |
Detect MF digits
Definition at line 32 of file dsp.h.
Referenced by ast_dsp_digitreset(), ast_dsp_new(), ast_dsp_process(), ast_dsp_set_digitmode(), and ss_thread().
| #define DSP_DIGITMODE_MUTECONF (1 << 9) |
Mute conference
Definition at line 35 of file dsp.h.
Referenced by ast_dsp_set_digitmode(), dahdi_setoption(), and store_config().
| #define DSP_DIGITMODE_MUTEMAX (1 << 10) |
Delay audio by a frame to try to extra quelch
Definition at line 36 of file dsp.h.
Referenced by ast_dsp_set_digitmode(), and dahdi_setoption().
| #define DSP_DIGITMODE_NOQUELCH (1 << 8) |
Do not quelch DTMF from in-band
Definition at line 34 of file dsp.h.
Referenced by ast_dsp_process(), and mgcp_new().
| #define DSP_DIGITMODE_RELAXDTMF (1 << 11) |
"Radio" mode (relaxed DTMF)
Definition at line 37 of file dsp.h.
Referenced by ast_dsp_process(), dahdi_setoption(), process_dahdi(), sip_new(), and store_config().
| #define DSP_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED) |
| #define DSP_FAXMODE_DETECT_CED (1 << 1) |
| #define DSP_FAXMODE_DETECT_CNG (1 << 0) |
| #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_DIGIT_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(), sip_new(), sip_rtp_read(), and store_config().
| #define DSP_FEATURE_FAX_DETECT (1 << 4) |
Definition at line 29 of file dsp.h.
Referenced by ast_dsp_process(), dahdi_new(), misdn_set_opt_exec(), read_config(), and sip_new().
| #define DSP_FEATURE_SILENCE_SUPPRESS (1 << 0) |
| #define DSP_FEATURE_WAITDIALTONE (1 << 20) |
Enable dial tone detection
Definition at line 44 of file dsp.h.
Referenced by ast_dsp_process(), dahdi_new(), and dahdi_read().
| #define DSP_PROGRESS_BUSY (1 << 18) |
Enable busy tone detection
Definition at line 41 of file dsp.h.
Referenced by __ast_dsp_call_progress().
| #define DSP_PROGRESS_CONGESTION (1 << 19) |
Enable congestion tone detection
Definition at line 42 of file dsp.h.
Referenced by __ast_dsp_call_progress().
| #define DSP_PROGRESS_RINGING (1 << 17) |
Enable calling tone detection
Definition at line 40 of file dsp.h.
Referenced by __ast_dsp_call_progress(), and pri_dchannel().
| #define DSP_PROGRESS_TALK (1 << 16) |
Enable talk detection
Definition at line 39 of file dsp.h.
Referenced by __ast_dsp_call_progress(), and dahdi_new().
| #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 |
| enum threshold |
Definition at line 62 of file dsp.h.
00062 { 00063 /* Array offsets */ 00064 THRESHOLD_SILENCE = 0, 00065 /* Always the last */ 00066 THRESHOLD_MAX = 1, 00067 };
| 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 1187 of file dsp.c.
References ast_debug, BUSY_MAX, BUSY_MIN, BUSY_PAT_PERCENT, BUSY_PERCENT, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, ast_dsp::busycount, ast_dsp::busymaybe, DSP_HISTORY, ast_dsp::historicnoise, and ast_dsp::historicsilence.
Referenced by ast_dsp_process().
01188 { 01189 int res = 0, x; 01190 #ifndef BUSYDETECT_TONEONLY 01191 int avgsilence = 0, hitsilence = 0; 01192 #endif 01193 int avgtone = 0, hittone = 0; 01194 if (!dsp->busymaybe) { 01195 return res; 01196 } 01197 for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) { 01198 #ifndef BUSYDETECT_TONEONLY 01199 avgsilence += dsp->historicsilence[x]; 01200 #endif 01201 avgtone += dsp->historicnoise[x]; 01202 } 01203 #ifndef BUSYDETECT_TONEONLY 01204 avgsilence /= dsp->busycount; 01205 #endif 01206 avgtone /= dsp->busycount; 01207 for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) { 01208 #ifndef BUSYDETECT_TONEONLY 01209 if (avgsilence > dsp->historicsilence[x]) { 01210 if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= dsp->historicsilence[x]) { 01211 hitsilence++; 01212 } 01213 } else { 01214 if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= dsp->historicsilence[x]) { 01215 hitsilence++; 01216 } 01217 } 01218 #endif 01219 if (avgtone > dsp->historicnoise[x]) { 01220 if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) { 01221 hittone++; 01222 } 01223 } else { 01224 if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) { 01225 hittone++; 01226 } 01227 } 01228 } 01229 #ifndef BUSYDETECT_TONEONLY 01230 if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) && 01231 (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && 01232 (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) { 01233 #else 01234 if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) { 01235 #endif 01236 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE 01237 if (avgtone > avgsilence) { 01238 if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) { 01239 res = 1; 01240 } 01241 } else { 01242 if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) { 01243 res = 1; 01244 } 01245 } 01246 #else 01247 res = 1; 01248 #endif 01249 } 01250 /* If we know the expected busy tone length, check we are in the range */ 01251 if (res && (dsp->busy_tonelength > 0)) { 01252 if (abs(avgtone - dsp->busy_tonelength) > (dsp->busy_tonelength*BUSY_PAT_PERCENT/100)) { 01253 #ifdef BUSYDETECT_DEBUG 01254 ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n", 01255 avgtone, dsp->busy_tonelength); 01256 #endif 01257 res = 0; 01258 } 01259 } 01260 #ifndef BUSYDETECT_TONEONLY 01261 /* If we know the expected busy tone silent-period length, check we are in the range */ 01262 if (res && (dsp->busy_quietlength > 0)) { 01263 if (abs(avgsilence - dsp->busy_quietlength) > (dsp->busy_quietlength*BUSY_PAT_PERCENT/100)) { 01264 #ifdef BUSYDETECT_DEBUG 01265 ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n", 01266 avgsilence, dsp->busy_quietlength); 01267 #endif 01268 res = 0; 01269 } 01270 } 01271 #endif 01272 #if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG) 01273 if (res) { 01274 ast_debug(5, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01275 } else { 01276 ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence); 01277 } 01278 #endif 01279 return res; 01280 }
Scans for progress indication in audio.
Definition at line 1111 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, ast_frame::ptr, and ast_frame::subclass.
01112 { 01113 if (inf->frametype != AST_FRAME_VOICE) { 01114 ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n"); 01115 return 0; 01116 } 01117 if (inf->subclass != AST_FORMAT_SLINEAR) { 01118 ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n"); 01119 return 0; 01120 } 01121 return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2); 01122 }
Return non-zero if DTMF hit was found.
| void ast_dsp_digitreset | ( | struct ast_dsp * | dsp | ) |
Reset DTMF detector.
Definition at line 1599 of file dsp.c.
References dtmf_detect_state_t::col_out, digit_detect_state_t::current_digits, dtmf_detect_state_t::current_hit, mf_detect_state_t::current_hit, dtmf_detect_state_t::current_sample, mf_detect_state_t::current_sample, ast_dsp::digit_state, ast_dsp::digitmode, digit_detect_state_t::digits, DSP_DIGITMODE_MF, digit_detect_state_t::dtmf, ast_dsp::dtmf_began, dtmf_detect_state_t::energy, goertzel_reset(), dtmf_detect_state_t::hits, mf_detect_state_t::hits, dtmf_detect_state_t::lasthit, digit_detect_state_t::mf, dtmf_detect_state_t::misses, dtmf_detect_state_t::row_out, s, digit_detect_state_t::td, and mf_detect_state_t::tone_out.
Referenced by ss_thread().
01600 { 01601 int i; 01602 01603 dsp->dtmf_began = 0; 01604 if (dsp->digitmode & DSP_DIGITMODE_MF) { 01605 mf_detect_state_t *s = &dsp->digit_state.td.mf; 01606 /* Reinitialise the detector for the next block */ 01607 for (i = 0; i < 6; i++) { 01608 goertzel_reset(&s->tone_out[i]); 01609 } 01610 s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0; 01611 s->current_sample = 0; 01612 } else { 01613 dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf; 01614 /* Reinitialise the detector for the next block */ 01615 for (i = 0; i < 4; i++) { 01616 goertzel_reset(&s->row_out[i]); 01617 goertzel_reset(&s->col_out[i]); 01618 } 01619 s->lasthit = s->current_hit = 0; 01620 s->energy = 0.0; 01621 s->current_sample = 0; 01622 s->hits = 0; 01623 s->misses = 0; 01624 } 01625 01626 dsp->digit_state.digits[0] = '\0'; 01627 dsp->digit_state.current_digits = 0; 01628 }
| 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 DAHDI 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 1744 of file dsp.c.
References ast_clear_flag, ast_dsp_free(), AST_FRFLAG_FROM_DSP, ast_dsp::destroy, and f.
Referenced by __frame_free().
01745 { 01746 struct ast_dsp *dsp; 01747 01748 ast_clear_flag(fr, AST_FRFLAG_FROM_DSP); 01749 01750 dsp = (struct ast_dsp *) (((char *) fr) - offsetof(struct ast_dsp, f)); 01751 01752 if (!dsp->destroy) 01753 return; 01754 01755 ast_dsp_free(dsp); 01756 }
| void ast_dsp_free | ( | struct ast_dsp * | dsp | ) |
Definition at line 1561 of file dsp.c.
References ast_free, AST_FRFLAG_FROM_DSP, ast_test_flag, ast_dsp::destroy, and ast_dsp::f.
Referenced by __ast_play_and_record(), __oh323_destroy(), ast_dsp_frame_freed(), background_detect_exec(), cl_dequeue_chan(), cleanup_connection(), conf_run(), dahdi_hangup(), destroy_endpoint(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_hangup(), record_exec(), sip_dtmfmode(), sip_hangup(), sip_rtp_read(), ss_thread(), and unload_module().
01562 { 01563 if (ast_test_flag(&dsp->f, AST_FRFLAG_FROM_DSP)) { 01564 /* If this flag is still set, that means that the dsp's destruction 01565 * been torn down, while we still have a frame out there being used. 01566 * When ast_frfree() gets called on that frame, this ast_trans_pvt 01567 * will get destroyed, too. */ 01568 01569 dsp->destroy = 1; 01570 01571 return; 01572 } 01573 ast_free(dsp); 01574 }
| int ast_dsp_get_tcount | ( | struct ast_dsp * | dsp | ) |
Get tcount (Threshold counter).
Definition at line 1692 of file dsp.c.
References ast_dsp::tcount.
Referenced by dahdi_read().
01693 { 01694 return dsp->tcount; 01695 }
| int ast_dsp_get_threshold_from_settings | ( | enum threshold | which | ) |
Get silence threshold from dsp.conf.
Definition at line 1729 of file dsp.c.
Referenced by app_exec(), ast_record_review(), conf_run(), do_waiting(), handle_recordfile(), load_config(), record_exec(), and setup_privacy_args().
01730 { 01731 return thresholds[which]; 01732 }
| int ast_dsp_get_tstate | ( | struct ast_dsp * | dsp | ) |
Get tstate (Tone State).
Definition at line 1687 of file dsp.c.
References ast_dsp::tstate.
Referenced by dahdi_read().
01688 { 01689 return dsp->tstate; 01690 }
| int ast_dsp_getdigits | ( | struct ast_dsp * | dsp, | |
| char * | buf, | |||
| int | max | |||
| ) |
Get pending DTMF/MF digits.
| int ast_dsp_init | ( | void | ) |
Load dsp settings from dsp.conf.
Definition at line 1734 of file dsp.c.
References _dsp_init().
Referenced by main().
01735 { 01736 return _dsp_init(0); 01737 }
| struct ast_dsp* ast_dsp_new | ( | void | ) | [read] |
Definition at line 1535 of file dsp.c.
References ast_calloc, ast_digit_detect_init(), ast_dsp_prog_reset(), ast_fax_detect_init(), ast_dsp::busycount, DEFAULT_THRESHOLD, ast_dsp::digit_state, ast_dsp::digitmode, ast_dsp::display_inband_dtmf_warning, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_FAXMODE_DETECT_CNG, DSP_FEATURE_SILENCE_SUPPRESS, DSP_HISTORY, ast_dsp::faxmode, ast_dsp::features, 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(), record_exec(), sip_dtmfmode(), sip_new(), and store_config().
01536 { 01537 struct ast_dsp *dsp; 01538 01539 if ((dsp = ast_calloc(1, sizeof(*dsp)))) { 01540 dsp->threshold = DEFAULT_THRESHOLD; 01541 dsp->features = DSP_FEATURE_SILENCE_SUPPRESS; 01542 dsp->busycount = DSP_HISTORY; 01543 dsp->digitmode = DSP_DIGITMODE_DTMF; 01544 dsp->faxmode = DSP_FAXMODE_DETECT_CNG; 01545 /* Initialize digit detector */ 01546 ast_digit_detect_init(&dsp->digit_state, dsp->digitmode & DSP_DIGITMODE_MF); 01547 dsp->display_inband_dtmf_warning = 1; 01548 /* Initialize initial DSP progress detect parameters */ 01549 ast_dsp_prog_reset(dsp); 01550 /* Initialize fax detector */ 01551 ast_fax_detect_init(dsp); 01552 } 01553 return dsp; 01554 }
Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise.
Definition at line 1300 of file dsp.c.
References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, s, and ast_frame::subclass.
Referenced by do_waiting().
01301 { 01302 short *s; 01303 int len; 01304 01305 if (f->frametype != AST_FRAME_VOICE) { 01306 ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n"); 01307 return 0; 01308 } 01309 if (f->subclass != AST_FORMAT_SLINEAR) { 01310 ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n"); 01311 return 0; 01312 } 01313 s = f->data.ptr; 01314 len = f->datalen/2; 01315 return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise); 01316 }
| struct ast_frame* ast_dsp_process | ( | struct ast_channel * | chan, | |
| struct ast_dsp * | dsp, | |||
| struct ast_frame * | inf | |||
| ) | [read] |
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 1319 of file dsp.c.
References __ast_dsp_call_progress(), __ast_dsp_silence_noise(), ast_channel::_softhangup, AST_ALAW, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_debug, 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_LIN2A, AST_LIN2MU, ast_log(), AST_MULAW, ast_queue_frame(), ast_set_flag, AST_SOFTHANGUP_DEV, ast_dsp::ced_tone_state, ast_dsp::cng_tone_state, digit_detect_state_t::current_digits, ast_frame::data, ast_frame::datalen, ast_dsp::digit_state, digit_detect_state_t::digitlen, ast_dsp::digitmode, digit_detect_state_t::digits, ast_dsp::display_inband_dtmf_warning, DSP_DIGITMODE_MF, DSP_DIGITMODE_NOQUELCH, DSP_DIGITMODE_RELAXDTMF, DSP_FAXMODE_DETECT_CED, DSP_FAXMODE_DETECT_CNG, DSP_FEATURE_BUSY_DETECT, DSP_FEATURE_CALL_PROGRESS, DSP_FEATURE_DIGIT_DETECT, DSP_FEATURE_FAX_DETECT, DSP_FEATURE_SILENCE_SUPPRESS, DSP_FEATURE_WAITDIALTONE, ast_dsp::dtmf_began, dtmf_detect(), fragment_t::end, ast_dsp::f, ast_dsp::faxmode, ast_dsp::features, ast_frame::frametype, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_frame::len, len(), LOG_WARNING, mf_detect(), ast_dsp::mute_data, ast_dsp::mute_fragments, ast_channel::name, ast_frame::ptr, SAMPLE_RATE, ast_frame::src, fragment_t::start, ast_frame::subclass, and tone_detect().
Referenced by dahdi_read(), mgcp_rtp_read(), oh323_rtp_read(), process_ast_dsp(), sip_rtp_read(), and usbradio_read().
01320 { 01321 int silence; 01322 int res; 01323 int digit = 0, fax_digit = 0; 01324 int x; 01325 short *shortdata; 01326 unsigned char *odata; 01327 int len; 01328 struct ast_frame *outf = NULL; 01329 01330 if (!af) { 01331 return NULL; 01332 } 01333 if (af->frametype != AST_FRAME_VOICE) { 01334 return af; 01335 } 01336 01337 odata = af->data.ptr; 01338 len = af->datalen; 01339 /* Make sure we have short data */ 01340 switch (af->subclass) { 01341 case AST_FORMAT_SLINEAR: 01342 shortdata = af->data.ptr; 01343 len = af->datalen / 2; 01344 break; 01345 case AST_FORMAT_ULAW: 01346 shortdata = alloca(af->datalen * 2); 01347 for (x = 0;x < len; x++) { 01348 shortdata[x] = AST_MULAW(odata[x]); 01349 } 01350 break; 01351 case AST_FORMAT_ALAW: 01352 shortdata = alloca(af->datalen * 2); 01353 for (x = 0; x < len; x++) { 01354 shortdata[x] = AST_ALAW(odata[x]); 01355 } 01356 break; 01357 default: 01358 /*Display warning only once. Otherwise you would get hundreds of warnings every second */ 01359 if (dsp->display_inband_dtmf_warning) 01360 ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass)); 01361 dsp->display_inband_dtmf_warning = 0; 01362 return af; 01363 } 01364 01365 /* Initially we do not want to mute anything */ 01366 dsp->mute_fragments = 0; 01367 01368 /* Need to run the silence detection stuff for silence suppression and busy detection */ 01369 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) { 01370 res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL); 01371 } 01372 01373 if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) { 01374 memset(&dsp->f, 0, sizeof(dsp->f)); 01375 dsp->f.frametype = AST_FRAME_NULL; 01376 ast_frfree(af); 01377 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01378 return &dsp->f; 01379 } 01380 if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) { 01381 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01382 memset(&dsp->f, 0, sizeof(dsp->f)); 01383 dsp->f.frametype = AST_FRAME_CONTROL; 01384 dsp->f.subclass = AST_CONTROL_BUSY; 01385 ast_frfree(af); 01386 ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name); 01387 ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); 01388 return &dsp->f; 01389 } 01390 01391 if ((dsp->features & DSP_FEATURE_FAX_DETECT)) { 01392 if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) { 01393 fax_digit = 'f'; 01394 } 01395 01396 if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) { 01397 fax_digit = 'e'; 01398 } 01399 } 01400 01401 if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) { 01402 if (dsp->digitmode & DSP_DIGITMODE_MF) 01403 digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); 01404 else 01405 digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF)); 01406 01407 if (dsp->digit_state.current_digits) { 01408 int event = 0, event_len = 0; 01409 char event_digit = 0; 01410 01411 if (!dsp->dtmf_began) { 01412 /* We have not reported DTMF_BEGIN for anything yet */ 01413 01414 if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { 01415 event = AST_FRAME_DTMF_BEGIN; 01416 event_digit = dsp->digit_state.digits[0]; 01417 } 01418 dsp->dtmf_began = 1; 01419 01420 } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) { 01421 /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */ 01422 if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { 01423 event = AST_FRAME_DTMF_END; 01424 event_digit = dsp->digit_state.digits[0]; 01425 event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE; 01426 } 01427 memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits); 01428 memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0])); 01429 dsp->digit_state.current_digits--; 01430 dsp->dtmf_began = 0; 01431 01432 if (dsp->features & DSP_FEATURE_BUSY_DETECT) { 01433 /* Reset Busy Detector as we have some confirmed activity */ 01434 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01435 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01436 ast_debug(1, "DTMF Detected - Reset busydetector\n"); 01437 } 01438 } 01439 01440 if (event) { 01441 memset(&dsp->f, 0, sizeof(dsp->f)); 01442 dsp->f.frametype = event; 01443 dsp->f.subclass = event_digit; 01444 dsp->f.len = event_len; 01445 outf = &dsp->f; 01446 goto done; 01447 } 01448 } 01449 } 01450 01451 if (fax_digit) { 01452 /* Fax was detected - digit is either 'f' or 'e' */ 01453 01454 memset(&dsp->f, 0, sizeof(dsp->f)); 01455 dsp->f.frametype = AST_FRAME_DTMF; 01456 dsp->f.subclass = fax_digit; 01457 outf = &dsp->f; 01458 goto done; 01459 } 01460 01461 if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) { 01462 res = __ast_dsp_call_progress(dsp, shortdata, len); 01463 if (res) { 01464 switch (res) { 01465 case AST_CONTROL_ANSWER: 01466 case AST_CONTROL_BUSY: 01467 case AST_CONTROL_RINGING: 01468 case AST_CONTROL_CONGESTION: 01469 case AST_CONTROL_HANGUP: 01470 memset(&dsp->f, 0, sizeof(dsp->f)); 01471 dsp->f.frametype = AST_FRAME_CONTROL; 01472 dsp->f.subclass = res; 01473 dsp->f.src = "dsp_progress"; 01474 if (chan) 01475 ast_queue_frame(chan, &dsp->f); 01476 break; 01477 default: 01478 ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res); 01479 } 01480 } 01481 } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) { 01482 res = __ast_dsp_call_progress(dsp, shortdata, len); 01483 } 01484 01485 done: 01486 /* Mute fragment of the frame */ 01487 for (x = 0; x < dsp->mute_fragments; x++) { 01488 memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start)); 01489 } 01490 01491 switch (af->subclass) { 01492 case AST_FORMAT_SLINEAR: 01493 break; 01494 case AST_FORMAT_ULAW: 01495 for (x = 0; x < len; x++) { 01496 odata[x] = AST_LIN2MU((unsigned short) shortdata[x]); 01497 } 01498 break; 01499 case AST_FORMAT_ALAW: 01500 for (x = 0; x < len; x++) { 01501 odata[x] = AST_LIN2A((unsigned short) shortdata[x]); 01502 } 01503 break; 01504 } 01505 01506 if (outf) { 01507 if (chan) { 01508 ast_queue_frame(chan, af); 01509 } 01510 ast_frfree(af); 01511 ast_set_flag(outf, AST_FRFLAG_FROM_DSP); 01512 return outf; 01513 } else { 01514 return af; 01515 } 01516 }
| int ast_dsp_reload | ( | void | ) |
Reloads dsp settings from dsp.conf.
Definition at line 1739 of file dsp.c.
References _dsp_init().
01740 { 01741 return _dsp_init(1); 01742 }
| void ast_dsp_reset | ( | struct ast_dsp * | dsp | ) |
Reset total silence count.
Definition at line 1630 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.
01631 { 01632 int x; 01633 01634 dsp->totalsilence = 0; 01635 dsp->gsamps = 0; 01636 for (x = 0; x < 4; x++) { 01637 dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0; 01638 } 01639 memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); 01640 memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); 01641 dsp->ringtimeout= 0; 01642 }
| void ast_dsp_set_busy_count | ( | struct ast_dsp * | dsp, | |
| int | cadences | |||
| ) |
Set number of required cadences for busy.
Definition at line 1581 of file dsp.c.
References ast_dsp::busycount, and DSP_HISTORY.
Referenced by dahdi_new().
01582 { 01583 if (cadences < 4) { 01584 cadences = 4; 01585 } 01586 if (cadences > DSP_HISTORY) { 01587 cadences = DSP_HISTORY; 01588 } 01589 dsp->busycount = cadences; 01590 }
| void ast_dsp_set_busy_pattern | ( | struct ast_dsp * | dsp, | |
| int | tonelength, | |||
| int | quietlength | |||
| ) |
Set expected lengths of the busy tone.
Definition at line 1592 of file dsp.c.
References ast_debug, ast_dsp::busy_quietlength, and ast_dsp::busy_tonelength.
Referenced by dahdi_new().
01593 { 01594 dsp->busy_tonelength = tonelength; 01595 dsp->busy_quietlength = quietlength; 01596 ast_debug(1, "dsp busy pattern set to %d,%d\n", tonelength, quietlength); 01597 }
| int ast_dsp_set_call_progress_zone | ( | struct ast_dsp * | dsp, | |
| char * | zone | |||
| ) |
Set zone for doing progress detection.
Definition at line 1668 of file dsp.c.
References aliases, ARRAY_LEN, ast_dsp_prog_reset(), progalias::mode, name, and ast_dsp::progmode.
Referenced by dahdi_new().
01669 { 01670 int x; 01671 01672 for (x = 0; x < ARRAY_LEN(aliases); x++) { 01673 if (!strcasecmp(aliases[x].name, zone)) { 01674 dsp->progmode = aliases[x].mode; 01675 ast_dsp_prog_reset(dsp); 01676 return 0; 01677 } 01678 } 01679 return -1; 01680 }
| int ast_dsp_set_digitmode | ( | struct ast_dsp * | dsp, | |
| int | digitmode | |||
| ) |
Set digit mode.
Definition at line 1644 of file dsp.c.
References ast_digit_detect_init(), ast_dsp::digit_state, ast_dsp::digitmode, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_DIGITMODE_MUTECONF, and DSP_DIGITMODE_MUTEMAX.
Referenced by dahdi_hangup(), dahdi_new(), dahdi_setoption(), mgcp_new(), mkintf(), sip_new(), ss_thread(), and store_config().
01645 { 01646 int new; 01647 int old; 01648 01649 old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01650 new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); 01651 if (old != new) { 01652 /* Must initialize structures if switching from MF to DTMF or vice-versa */ 01653 ast_digit_detect_init(&dsp->digit_state, new & DSP_DIGITMODE_MF); 01654 } 01655 dsp->digitmode = digitmode; 01656 return 0; 01657 }
| int ast_dsp_set_faxmode | ( | struct ast_dsp * | dsp, | |
| int | faxmode | |||
| ) |
Set fax mode.
Definition at line 1659 of file dsp.c.
References ast_fax_detect_init(), and ast_dsp::faxmode.
01660 { 01661 if (dsp->faxmode != faxmode) { 01662 ast_fax_detect_init(dsp); 01663 } 01664 dsp->faxmode = faxmode; 01665 return 0; 01666 }
| void ast_dsp_set_features | ( | struct ast_dsp * | dsp, | |
| int | features | |||
| ) |
Select feature set.
Definition at line 1556 of file dsp.c.
References ast_dsp::features.
Referenced by __oh323_new(), dahdi_new(), dahdi_read(), disable_dtmf_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), pri_dchannel(), read_config(), sip_dtmfmode(), sip_new(), sip_rtp_read(), ss7_linkset(), and store_config().
01557 { 01558 dsp->features = features; 01559 }
| void ast_dsp_set_threshold | ( | struct ast_dsp * | dsp, | |
| int | threshold | |||
| ) |
Set threshold value for silence.
Definition at line 1576 of file dsp.c.
References ast_dsp::threshold.
Referenced by __ast_play_and_record(), do_waiting(), handle_recordfile(), isAnsweringMachine(), and record_exec().
Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence.
Definition at line 1282 of file dsp.c.
References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, s, and ast_frame::subclass.
Referenced by __ast_play_and_record(), background_detect_exec(), conf_run(), do_waiting(), handle_recordfile(), isAnsweringMachine(), and record_exec().
01283 { 01284 short *s; 01285 int len; 01286 01287 if (f->frametype != AST_FRAME_VOICE) { 01288 ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n"); 01289 return 0; 01290 } 01291 if (f->subclass != AST_FORMAT_SLINEAR) { 01292 ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n"); 01293 return 0; 01294 } 01295 s = f->data.ptr; 01296 len = f->datalen/2; 01297 return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL); 01298 }
| int ast_dsp_was_muted | ( | struct ast_dsp * | dsp | ) |
Returns true if DSP code was muting any fragment of the last processed frame. Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio.
Definition at line 1682 of file dsp.c.
References ast_dsp::mute_fragments.
Referenced by dahdi_read().
01683 { 01684 return (dsp->mute_fragments > 0); 01685 }
1.5.9