Asterisk SIT Detection
A few years ago I implemented an instance of VICIdial for a company I was working for who were setting up a call centre to do work for a new client. The outbound connection from Asterisk to the PSTN was SIP trunks into a few providers who themselves connected to various US carriers over a variety of technologies.
The work that was being done was dealing with some potentially old data, so it was expected that when calling the customers there would be a measurable number of disconnected numbers, the client from their own operations over PRI and past experience with call centers had an expected percentage of call attempts that would hit disconnected numbers and wanted to be able to mark the numbers in their database as disconnected to avoid wasting time and money on trying to call them in the future. Up to this point everything was good and understandable. However, as the work kicked off, the percentage of calls that we made that were detected as being disconnected was surprisingly low, extremely low, something that the client was quick to pick up on.
I started investigating and worked out that when calling a bad number most of the time we would a SIP 183 Progress message with early audio where the audio was a voice message of varying levels of detail, length and codes with an SIT typically contained somewhere in the message. Very occasionally we'd get an immediate bad response which was what we wanted. Sometimes there would be a short message followed by a quick call termination with a response that allowed us to determine the number was out of service. Most of the time however the message received was long and repeated and ended with no useful response code, or almost as useless, the call ended after 3 minutes with a number out of service response.
So, in summary, I was getting a random selection of legacy failure handling from various telcos as presented over various technologies.
I asked our providers if there was anything they could do to just pass us nice quick SIP 404 responses or similar, but, they were just passing what they received and were unable to do anything to help, well, one did offer run our calls through SIT detection on their end for a huge cost, something the project couldn't afford.
With the idea of SIT detection and knowing from the earlier investigation that most of the audio feedback did include at least one SIT at some point, I looked at what Asterisk could do.
Unfortunately, progress detection is only available over DAHDI channels, in this case we were using SIP, so not so useful. I had a look at potential addon modules, things like fax detection seemed to be closest to what I needed, implemented with simple dsp tone detection, but, they could only work on audio after a call had been answered, not before. I looked at commercial products, Sangoma CPD was recommended by the VICIdial developers, but at the time, it was a Windows package, the idea of buying two new servers (to avoid a single point of failure), Windows Server licenses and two copies of Sangoma's product was more of a turnoff to the business than the idea of putting Windows boxes into the middle of a nice stable Linux solution was a turnoff to me.
So, the only solution left was to hack something together myself.
I modified app_dial.c adding an option to enable SIT detection using a DSP, fixed a long standing bug in the asterisk DSP progress detection that prevented it from being able to detect an SIT, and started testing. After a couple of iterations, I had something that worked, it wasn't pretty, it had some issues, but it worked pretty damn well and was stable.
I put it live and away it ran for a couple of years.
I wanted to contribute this back to Asterisk, the DSP progress detection fix was taken OK, but, the app_dial.c mods were too nasty for me to even submit, I was sure there must be a better way and looked for ways to implement it better such that it could be contributed. The fact that we needed Asterisk 1.4 to work with VICIdial, that Asterisk was progressing pretty quickly at the time, and that I was then busy with other, unrelated things led to little progress being made in making a nice submittable patch.
Now, that call centre has gone along with the code I wrote...
Someone called Joshua contacted me last week, basically in the same boat as I was, he needed to be able to detect SITs on SIP early media and asked if I'd ever got something usable completed and if not, could I help him out.
So, without any of the original code left and a very vague recollection of what I did years ago, I've had a little bit of a play with the app_dial.c code from the Asterisk 1.4 branch as that's what Joshua is using... I've got something that's even uglier than before, that probably has even more issues that before, but, in my very very limited testing, it does actually work...
So... I'm posting it here in all it's nasty hackish glory... Hopefully someone who has more of an idea of what AudioHooks or FrameHooks are supposed to do, or has a better idea of the magic relating to transcoding of early media or both can make something useful from this...
The files are: