From 2bc067a7404a23789e4af73ef21d27a10553f2ae Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Sat, 26 Mar 2005 07:12:19 +0000 Subject: Implement fax detect within i4l (bug #3827) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5265 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_modem_i4l.c | 28 ++++++++++++++++++++++++++-- include/asterisk/vmodem.h | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/channels/chan_modem_i4l.c b/channels/chan_modem_i4l.c index d268d9c58..bb032e2b5 100755 --- a/channels/chan_modem_i4l.c +++ b/channels/chan_modem_i4l.c @@ -27,6 +27,7 @@ #include #include #include +#include #define STATE_COMMAND 0 #define STATE_VOICE 1 @@ -105,7 +106,7 @@ static int i4l_startrec(struct ast_modem_pvt *p) p->dsp = ast_dsp_new(); if (p->dsp) { ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev); - ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT); + ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT); ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0); } } @@ -451,6 +452,29 @@ static struct ast_frame *i4l_read(struct ast_modem_pvt *p) f = ast_dsp_process(p->owner, p->dsp, &p->fr); if (f && (f->frametype == AST_FRAME_DTMF)) { ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c on %s\n", f->subclass, p->dev); + if (f->subclass == 'f') { + /* Fax tone -- Handle and return NULL */ + struct ast_channel *ast = p->owner; + if (!p->faxhandled) { + p->faxhandled++; + if (strcmp(ast->exten, "fax")) { + if (ast_exists_extension(ast, ast_strlen_zero(ast->macrocontext) ? ast->context : ast->macrocontext, "fax", 1, ast->cid.cid_num)) { + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name); + /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */ + pbx_builtin_setvar_helper(ast,"FAXEXTEN",ast->exten); + if (ast_async_goto(ast, ast->context, "fax", 1)) + ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, ast->context); + } else + ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n"); + } else + ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n"); + } else + ast_log(LOG_DEBUG, "Fax already handled\n"); + p->fr.frametype = AST_FRAME_NULL; + p->fr.subclass = 0; + f = &p->fr; + } return f; } } @@ -553,7 +577,7 @@ static int i4l_answer(struct ast_modem_pvt *p) p->dsp = ast_dsp_new(); if (p->dsp) { ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev); - ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT); + ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT); ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0); } } diff --git a/include/asterisk/vmodem.h b/include/asterisk/vmodem.h index 517af6d7f..e45b981cd 100755 --- a/include/asterisk/vmodem.h +++ b/include/asterisk/vmodem.h @@ -100,6 +100,8 @@ struct ast_modem_pvt { int escape; /*! flag to say if has caller*id yet*/ int gotclid; + /* Has a fax tone already been handled? */ + int faxhandled; /*! ringer timeout */ int ringt; /*! actual time of last ring */ -- cgit v1.2.3