login | register
Wed 09 of Jul, 2008 [05:58 UTC]

voip-info.org

History

NVFaxDetect

Created by: justin_newman,Last modification on Thu 22 of Nov, 2007 [17:51 UTC] by jq53333

Fax Detection for IAX/SIP/ZAP

Including non-silence and digit detection.

Download

You can find the code and more instructions on the web.

Synopsis

 Detects fax sounds on all channel types (on IAX and SIP too)

Description

 NVFaxDetect([waitdur[|options[|sildur[|mindur[|maxdur]]]]])

This application listens for fax tones (on IAX and SIP channels too) for waitdur seconds of time. In addition, it can be interrupted by digits, or non-silence. Audio is only monitored in the receive direction. If digits interrupt, they must be the start of a valid extension unless the option is included to ignore. If fax is detected, it will jump to the 'fax' extension. If a period of non-silence greater than 'mindur' ms, yet less than 'maxdur' ms is followed by silence at least 'sildur' ms then the app is aborted and jumps to the 'talk' extension. If all undetected, control will continue at the next priority.

Parameters

     waitdur:  Maximum number of seconds to wait (default=4)
     options:
       'n':  Attempt on-hook if unanswered (default=no)
       'x':  DTMF digits terminate without extension (default=no)
       'd':  Ignore DTMF digit detection (default=no)
       'f':  Ignore fax detection (default=no)
       't':  Ignore talk detection (default=no)
     sildur:  Silence ms after mindur/maxdur before aborting (default=1000)
     mindur:  Minimum non-silence ms needed (default=100)
     maxdur:  Maximum non-silence ms allowed (default=0/forever)

Return codes

Returns -1 on hangup, and 0 on successful completion with no exit conditions.

Notes

This code is NOT included with Asterisk at this point, however it is free. To get it, please search for it on the web.

This should only work on channels that are using ULAW/ALAW.

Requirements

  • Asterisk development or stable

Sample Usage (extensions.conf)

[context-incoming]
; Answer and do some detection work
exten => s,1,Answer
exten => s,2,NVFaxDetect()
exten => s,3,Hangup

; If user presses "1", dial main line
exten => 1,1,Dial(SIP/5500)
exten => 1,2,Hangup

; If this is a fax, dial fax line
exten => fax,1,Dial(SIP/5501)
exten => fax,2,Hangup

; If user is talking, send him to Debra
exten => talk,1,Dial(SIP/5502)
exten => talk,2,Hangup


Another Example (extensions.conf)

; ring extensions with fax detect
[macro-faxexten]
exten => s,1,Dial(${ARG1},17) ; wait 3 rings
exten => s,2,Answer
exten => s,3,Playtones(ring) ; play fake ring so caller doesn't wonder whats going on
exten => s,4,NVFaxDetect(4|dt) ; while playing ring sound, detect faxes for 4 seconds (goes to "fax" extension if detected)
exten => s,5,Goto(s-${DIALSTATUS},1) ; if no fax, branch on dialstatus
exten => s-NOANSWER,1,Voicemail(u${MACRO_EXTEN})
exten => s-NOANSWER,2,Hangup()
exten => s-BUSY,1,Voicemail(b${MACRO_EXTEN})
exten => s-BUSY,2,Hangup()
exten => _s-.,1,Goto(s-NOANSWER,1) ; everything else is treated as no answer

; If this is a fax, get it
exten => fax,1,StopPlaytones ; you must do this or it will play ring sounds over your fax
exten => fax,2,SetVar(FAXFILE=/var/spool/asterisk/fax/${DNID}_${UNIQUEID})
exten => fax,3,Goto(fax,s,1)

[fax]
exten => s,1,rxfax(${FAXFILE}.tif)
exten => h,1,DEADAGI(faxtoemail.agi|${FAXFILE}.tif) ; you need to download the faxtoemail script or something similar here.

Installation

Easiest way to get up and running:

(1) Drop the code in your /usr/src/asterisk/apps directory

(2) Edit the Makefile in the apps directory. Add the following line:
    APPS+=app_nv_faxdetect.so

(3) Go to /usr/src/asterisk and run "make", then run "make install"
    If you encounter compiler errors like:

          error: struct ast_channel has no member cid

    Edit app_nv_faxdetect.c and enable the CALLERID_FIELD #define statement:

         #define CALLERID_FIELD cid.cid_num

   Comment out the other, existing definition.

(4) Start or restart Asterisk

(5) Type "show application nvfaxdetect" from the CLI and you should see it



There may be a better way to do this; however, this is what I used to get it working under FreeBSD.

Now cd /usr/ports/distfiles

go ahead and extract the asterisk-1.2.7.1.tar.gz file with

tar -zxvf asterisk-1.2.7.1.tar.gz

cd asterisk-1.2.7.1/apps

vi Makefile

add the following to the list of modules to compile app_nv_backgrounddetect.so app_nv_faxdetectc.so

write the file

Then add the following before file.h in in both app_nv_backgrounddetect.c and app_nv_faxdetect.c

  1. include <stdio.h>

cd ../../..

(You should now be in /usr/ports/distfiles/ )

tar cf asterisk-1.2.7.1.tar asterisk-1.2.7.1

and then compress with

gzip asterisk-1.2.7.1.tar (if it exists, you will need to write over it)

Now cd /usr/ports/net/asterisk

rename the distinfo file to distinfo.old so it wont get used when you begin compiling.

make clean ; make deinstall ; make ; make install

asterisk -vvvgc

asterisk> show modules

You should see the two modules now.


-Greg






Future Improvements

We are finishing up outgoing fax detect. Look for the patch or new file there.

See also


Comments

Comments Filter
222

333Re. the 'Fax detected by no fax extension' issue

by lemob, Tuesday 12 of December, 2006 [20:21:03 UTC]
Make sure that you have an appropriate "exten => fax" entry in the context from which NVFaxDetect is called. From what I can see, the behavior that dictates jumping to this label is hard-coded. The "exten => fax" label must exist and include logic that will appropriately handle the fax.
FWIW, the default zapata.conf in TrixBox 2.0 puts incoming Zap calls in the "from-zaptel" context. While "from-pstn" has the proper fax extension, from-zaptel does not. Once we added the line:
exten => fax,1,Goto(ext-fax,in_fax,1)
to from-zaptel, things started working.
222

333Detecting but no fax extension

by jpff, Monday 27 of November, 2006 [07:29:10 UTC]
Following the excellent installation instructions I have NVFaxDetect installed and it clearly runs. But...(and there had to be a but!) I have the twin messages

2006-04-22 12:08:17 NOTICE15648: app_nv_faxdetect.c:216 nv_detectfax_exec: Redirecting SIP/gw02.uk.sipgate.net-4191b8c0 to fax extension
2006-04-22 12:08:17 WARNING15648: app_nv_faxdetect.c:224 nv_detectfax_exec: Fax detected, but no fax extension

This confuses me as I clearly have a fax extension
...........

Much later ...... I seem to have got over this with a version upgrade and building from source.
Now on to why rxfax is failing!

==John ff
222

333Not detecting fax

by sandermax, Wednesday 15 of March, 2006 [05:37:29 UTC]
Asterisk@home 2.7 everything working (even canadian weather thanks - http://lists.digium.com/pipermail/asterisk-users/2005-September/117619.html) except the fax detection.
Have followed directions and installed as per above and I get this in the log
Mar 14 21:29:05 VERBOSE5228 logger.c: — Executing Goto("IAX2/FreeWorldTel-Out-3", "from-pstn-afthours|s|1") in new stack
Mar 14 21:29:05 VERBOSE5228 logger.c: — Goto (from-pstn-afthours,s,1)
Mar 14 21:29:05 DEBUG5228 pbx.c: Expression result is '0'
Mar 14 21:29:05 VERBOSE5228 logger.c: — Executing GotoIf("IAX2/FreeWorldTel-Out-3", "0?from-pstn-afthours-nofax|s|1:2") in new stack
Mar 14 21:29:05 VERBOSE5228 logger.c: — Goto (from-pstn-afthours,s,2)
Mar 14 21:29:05 VERBOSE5228 logger.c: — Executing Answer("IAX2/FreeWorldTel-Out-3", "") in new stack
Mar 14 21:29:05 VERBOSE5228 logger.c: — Executing PlayTones("IAX2/FreeWorldTel-Out-3", "ring") in new stack
Mar 14 21:29:05 DEBUG5228 channel.c: Scheduling timer at 160 sample intervals
Mar 14 21:29:05 VERBOSE5228 logger.c: — Executing NVFaxDetect("IAX2/FreeWorldTel-Out-3", "40") in new stack
Mar 14 21:29:05 DEBUG5228 app_nv_faxdetect.c: Preparing detect of fax (waitdur=40ms, sildur=1000ms, mindur=100ms, maxdur=-1ms)
Mar 14 21:29:05 DEBUG5059 chan_iax2.c: Ooh, voice format changed to 16
Mar 14 21:29:05 DEBUG5228 channel.c: Generator got voice, switching to phase locked mode
Mar 14 21:29:05 DEBUG5228 channel.c: Scheduling timer at 0 sample intervals
Mar 14 21:29:05 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:06 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:07 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:08 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:09 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:10 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:11 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:12 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:13 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:14 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:15 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:16 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 20 ms
Mar 14 21:29:17 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:18 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:19 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:20 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:21 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:22 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 19 ms
Mar 14 21:29:25 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:26 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:27 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:28 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:31 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:32 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:33 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:34 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
Mar 14 21:29:35 DEBUG5059 chan_iax2.c: Received VNAK: resending outstanding frames
Mar 14 21:29:37 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:38 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms
an_iax2.c: Ooh, voice format changed to 16Mar 14 21:29:39 DEBUG5228 app_nv_faxdetect.c: Start of voice token!
Mar 14 21:29:40 DEBUG5228 app_nv_faxdetect.c: Found unqualified token of 0 ms


I even changed the detection time to 40MS!! Still won't pick-up. Any Ideas?
222

333Cannot Get Registered?

by chadeguchi, Wednesday 22 of February, 2006 [00:24:21 UTC]
Hello everyone,

Been working with Asterisk for awhile now, but can't get the application to register. Seems to compile fine with make && make install, but will not show as registered. Any suggestions? Thanks!
222

333Re: Should be in CVS

by lschweiss, Friday 03 of February, 2006 [01:28:26 UTC]
Not really. I can't blame Newman Telecom for keeping this out. Getting this in Asterisk requires signing copyright over to Digium.


222

333NVFaxDetect on Asterisk 1.2 (and/or AMP or @home Beta)

by justin_newman, Thursday 24 of November, 2005 [00:05:33 UTC]
If you are unable to build NVFaxDetect and/or NVBackgroundDetect on Asterisk
1.2 (and/or AMP or @home Beta), make the following changes:

1) Above the following line near the top, in both files:

   #include <asterisk/lock.h>

   Add:

   #include <stdio.h>

2) In NVBackgroundDetect, to get rid of the trigraph warning, search for
"??)" and replace it with "?)".

3) Rebuild Asterisk from /usr/src/asterisk with "make && make install".

4) Restart Asterisk with "restart now" from the CLI.

The new release will have this modification.

Justin
222

333Simpler way to install on Debian (Sarge)

by schlika, Monday 21 of November, 2005 [20:12:27 UTC]
I successfully installed this app on Debian Sarge using the following method, keeping the official packages :

Install the official sarge asterisk packages : apt-get install asterisk asterisk-dev
Download app_nv_faxdetect.c, edit and replace "#define CALLERID_FIELD cid.cid_num" by "#define CALLERID_FIELD callerid"
Compile it using "gcc -D_GNU_SOURCE -shared -o app_nv_faxdetect.so app_nv_faxdetect.c"
Copy the resulting app_nv_faxdetect.so to /usr/lib/asterisk/modules/

Restart asterisk and enjoy :-)
222

333Re: Should be in CVS

by PeaCeKeePa, Thursday 21 of April, 2005 [18:32:18 UTC]
Got this app rockin using asterisk@home v0.9, not included but works... check the asterisk@home forum on sourceforge - topic Fax
222

333Should be in CVS

by bjornta, Thursday 31 of March, 2005 [03:32:10 UTC]
I really hope the Asterisk team will add this to asterisk-addons in CVS.
This app rocks!
Not everyone gets their faxes through a ZAP card, or can assign a DID just for fax.

Bjorn