[asterisk-commits] irroot: branch irroot/distrotech-customers-trunk r338947 - /team/irroot/distr...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Oct 2 17:15:36 CDT 2011
Author: irroot
Date: Sun Oct 2 17:15:33 2011
New Revision: 338947
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=338947
Log:
Remove WaitFAX application its not needed
Remove locking its not needed
Remove gateway caps on turning off faxgateway
Modified:
team/irroot/distrotech-customers-trunk/res/res_fax.c
Modified: team/irroot/distrotech-customers-trunk/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-trunk/res/res_fax.c?view=diff&rev=338947&r1=338946&r2=338947
==============================================================================
--- team/irroot/distrotech-customers-trunk/res/res_fax.c (original)
+++ team/irroot/distrotech-customers-trunk/res/res_fax.c Sun Oct 2 17:15:33 2011
@@ -228,33 +228,10 @@
<ref type="application">SendFax</ref>
</see-also>
</function>
- <application name="WaitFAX" language="en_US">
- <synopsis>
- Generic Fax Detect CNG/T.38 (Wait For Fax)
- </synopsis>
- <syntax>
- <parameter name="timeout" required="true">
- <para>Specifies the number of seconds we attempt to detect a fax tone on the channel</para>
- </parameter>
- <parameter name="tone" required="false">
- <para>Either the tone name defined in the "indications.conf" configuration file,
- or a directly specified list of frequencies and durations.</para>
- <para>If not specified silence is generated.</para>
- </parameter>
- <parameter name="noise" required="false">
- <para>Number of ms noise detected before proceeding with the dialplan.</para>
- </parameter>
- </syntax>
- <description>
- <para>This application sets FAXOPT(status) To SUCCESS | FAILURE | ERROR</para>
- <para>FAXOPT(statusstr) will be set to CNG | T38 on SUCCESS or reason on FAILURE | ERROR</para>
- </description>
- </application>
***/
static const char app_receivefax[] = "ReceiveFAX";
static const char app_sendfax[] = "SendFAX";
-static const char app_waitfax[] = "WaitFAX";
struct debug_info_history {
unsigned int consec_frames;
@@ -3158,12 +3135,8 @@
}
ast_dsp_set_features(faxdetect->dsp, DSP_FEATURE_FAX_DETECT);
- if (noiselim) {
- ast_dsp_set_faxmode(faxdetect->dsp, dsp_detect_flag || DSP_FAXMODE_DETECT_SQUELCH);
- ast_dsp_set_threshold(faxdetect->dsp, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE));
- } else {
- ast_dsp_set_faxmode(faxdetect->dsp, dsp_detect_flag);
- }
+ ast_dsp_set_faxmode(faxdetect->dsp, dsp_detect_flag || DSP_FAXMODE_DETECT_SQUELCH);
+ ast_dsp_set_threshold(faxdetect->dsp, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE));
return faxdetect;
}
@@ -3198,7 +3171,6 @@
switch (event) {
case AST_FRAMEHOOK_EVENT_ATTACHED:
/* Setup format for DSP on ATTACH*/
- ao2_lock(faxdetect);
ast_format_copy(&faxdetect->orig_format, &chan->readformat);
switch (chan->readformat.id) {
case AST_FORMAT_SLINEAR:
@@ -3209,18 +3181,16 @@
if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
ast_framehook_detach(chan, details->faxdetect_id);
details->faxdetect_id = -1;
+ return f;
}
}
- ao2_unlock(faxdetect);
return NULL;
case AST_FRAMEHOOK_EVENT_DETACHED:
/* restore audio formats when we are detached */
- ao2_lock(faxdetect);
ast_set_read_format(chan, &faxdetect->orig_format);
if ((peer = ast_bridged_channel(chan))) {
ast_channel_make_compatible(chan, peer);
}
- ao2_unlock(faxdetect);
return NULL;
case AST_FRAMEHOOK_EVENT_READ:
if (f) {
@@ -3229,11 +3199,16 @@
default:
return f;
};
+
+ if (details->faxdetect_id < 0) {
+ return f;
+ }
if ((!ast_tvzero(faxdetect->timeout_start) &&
(ast_tvdiff_ms(ast_tvnow(), faxdetect->timeout_start) > faxdetect->timeout))) {
ast_framehook_detach(chan, details->faxdetect_id);
details->faxdetect_id = -1;
+ return f;
}
/* only handle VOICE and CONTROL frames*/
@@ -3258,7 +3233,6 @@
return f;
}
- ao2_lock(faxdetect);
if (f->frametype == AST_FRAME_VOICE) {
f = ast_dsp_process(chan, faxdetect->dsp, f);
if (f->frametype == AST_FRAME_DTMF) {
@@ -3308,8 +3282,6 @@
details->faxdetect_id = -1;
}
- ao2_unlock(faxdetect);
-
return f;
}
@@ -3359,170 +3331,6 @@
ao2_ref(faxdetect, 1);
return faxdetect;
}
-
-/*! \brief Faxdetect loop used by WaitFAX
- * \details Run DSP faxdetect on the channel for timeout seconds or until fax is detected
- * \param chan channel to run fax detect on
- * \param timeout maximum time to wait for fax detection
- * \return 0 if nothing was detected 1 on CNG detected 2 if T38 negotiation is started -1 on error*/
-static int do_waitfax_exec(struct ast_channel *chan, int timeout, int noiselim)
-{
- int timeleft = timeout;
- int res = 0;
- struct ast_frame *f, *dup_f;
- AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames;
- struct fax_detect *faxdetect = NULL;
-
- if (!(faxdetect = fax_detect_attach(chan, 0, noiselim, DSP_FAXMODE_DETECT_CNG))) {
- return -1;
- }
-
- AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
-
- while ((timeleft = ast_waitfor(chan, timeleft))) {
- if (!(f = ast_read(chan))) {
- break;
- }
-
- ao2_lock(faxdetect);
- switch (faxdetect->result) {
- case 'f':
- res = 1;
- break;
- case 't':
- res = 2;
- break;
- case 'n':
- break;
- }
- ao2_unlock(faxdetect);
-
- if (ast_is_deferrable_frame(f)) {
- AST_LIST_INSERT_HEAD(&deferred_frames, f, frame_list);
- } else {
- ast_frfree(f);
- }
-
- if (res) {
- break;
- }
- }
- ao2_ref(faxdetect, -1);
-
- ast_channel_lock(chan);
- while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) {
- dup_f = ast_frisolate(f);
- ast_queue_frame_head(chan, dup_f);
- if (dup_f != f) {
- ast_frfree(f);
- }
- }
- ast_channel_unlock(chan);
-
- return res;
-}
-
-/*! \brief Alternate wait app that listens for CNG
- * \details This app answers the channel and waits for CNG tone or T38 negotiation
- * if the channel driver supports faxdetect it will proceed to the fax
- * extension.
- * it will set FAXOPT(status) and FAXOPT(statusstr) allowing dial plan processing where
- * the channel does not have fax detect or the Dialplan needs to handle faxdetection
- *
- * \param chan channel this application is called on
- * \param data the paramaters passed to the application
- * \return this application will always return 0
- */
-static int waitfax_exec(struct ast_channel *chan, const char *data)
-{
- int res = 0;
- unsigned int timeout;
- unsigned int noiselim;
- int ptres = -1;
- char *parse;
- struct ast_fax_session_details *details;
- struct ast_silence_generator *silgen = NULL;
- struct ast_tone_zone_sound *ts;
-
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(timeout);
- AST_APP_ARG(tone);
- AST_APP_ARG(noise);
- );
-
- if (!(details = find_or_create_details(chan))) {
- ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
- return 0;
- }
-
- parse = ast_strdupa(data);
- AST_STANDARD_APP_ARGS(args, parse);
-
- if (!ast_strlen_zero(args.timeout) && sscanf(args.timeout, "%u", &timeout) == 1) {
- timeout = timeout * 1000;
- } else {
- timeout = 0;
- }
-
- if (timeout <= 0) {
- ast_string_field_set(details, result, "ERROR");
- ast_string_field_set(details, resultstr, "Invalid timeout in WaitFAX");
- ast_log(LOG_ERROR, "Application WaitFAX requires a valid timeout\n");
- ao2_ref(details, -1);
- return 0;
- }
-
- if (ast_strlen_zero(args.noise) || sscanf(args.noise, "%u", &noiselim) != 1) {
- noiselim = 0;
- }
-
- if (chan->_state != AST_STATE_UP) {
- ast_answer(chan);
- }
-
- /* If no other generator is present, start tone or silencegen while waiting */
- if (!chan->generatordata && !ast_strlen_zero(args.tone)) {
- if ((ts = ast_get_indication_tone(chan->zone, args.tone))) {
- ptres = ast_playtones_start(chan, 0, ts->data, 0);
- ts = ast_tone_zone_sound_unref(ts);
- } else {
- ptres = ast_playtones_start(chan, 0, args.tone, 0);
- }
- if (!ptres && ast_opt_transmit_silence) {
- silgen = ast_channel_start_silence_generator(chan);
- }
- } else if (ast_opt_transmit_silence && !chan->generatordata) {
- silgen = ast_channel_start_silence_generator(chan);
- }
-
- res = do_waitfax_exec(chan, timeout, noiselim);
-
- /* stop silgen or tones if present */
- if (silgen) {
- ast_channel_stop_silence_generator(chan, silgen);
- } else if (!ptres) {
- ast_playtones_stop(chan);
- }
-
- if (res > 0) {
- ast_string_field_set(details, result, "SUCCESS");
- if (res == 1) {
- ast_string_field_set(details, resultstr, "CNG");
- } else {
- ast_string_field_set(details, resultstr, "T38");
- }
- } else if (res < 0) {
- ast_string_field_set(details, result, "ERROR");
- ast_string_field_set(details, resultstr, "DSP Error WaitFAX Failed");
- } else {
- ast_string_field_set(details, result, "FAILED");
- ast_string_field_set(details, resultstr, "No CNG Tone Or T38 Detected");
- }
-
- ao2_ref(details, -1);
- return 0;
-}
-
/*! \brief hash callback for ao2 */
static int session_hash_cb(const void *obj, const int flags)
@@ -3925,6 +3733,8 @@
} else if (!strcasecmp(data, "t38gateway") || !strcasecmp(data, "gateway") ||
!strcasecmp(data, "t38_gateway") || !strcasecmp(data, "faxgateway")) {
ast_copy_string(buf, details->gateway_id != -1 ? "yes" : "no", len);
+ } else if (!strcasecmp(data, "faxdetect")) {
+ ast_copy_string(buf, details->faxdetect_id != -1 ? "yes" : "no", len);
} else if (!strcasecmp(data, "error")) {
ast_copy_string(buf, details->error, len);
} else if (!strcasecmp(data, "filename")) {
@@ -4033,6 +3843,7 @@
} else if (ast_false(val)) {
ast_framehook_detach(chan, details->gateway_id);
details->gateway_id = -1;
+ details->caps &= ~AST_FAX_TECH_GATEWAY;
} else {
ast_log(LOG_WARNING, "Unsupported value '%s' passed to FAXOPT(%s).\n", value, data);
}
@@ -4120,10 +3931,6 @@
ast_log(LOG_WARNING, "failed to unregister '%s'\n", app_receivefax);
}
- if (ast_unregister_application(app_waitfax) < 0) {
- ast_log(LOG_WARNING, "failed to unregister '%s'\n", app_waitfax);
- }
-
if (fax_logger_level != -1) {
ast_logger_unregister_level("FAX");
}
@@ -4164,10 +3971,6 @@
return AST_MODULE_LOAD_DECLINE;
}
- if (ast_register_application_xml(app_waitfax, waitfax_exec) < 0) {
- ast_log(LOG_WARNING, "failed to register '%s'.\n", app_waitfax);
- }
-
ast_cli_register_multiple(fax_cli, ARRAY_LEN(fax_cli));
res = ast_custom_function_register(&acf_faxopt);
fax_logger_level = ast_logger_register_level("FAX");
More information about the asterisk-commits
mailing list