FreeSWITCH is a Software Defined Telecom Stack enabling the digital transformation from proprietary telecom switches to a versatile software implementation that runs on any commodity hardware. From a Raspberry PI to a multi-core server, FreeSWITCH can unl
Go to file
Stefan Knoblich 705543c8b4 ftmod_misdn: Use a per-span I/O thread to handle B-channel data.
Move the B-channel message handling into a per-span I/O thread,
to solve most of the problems caused by the intermixed data + control
socket interface of mISDN, missing write poll() support on
mISDN B-channels and the FreeTDM I/O model. This eliminates most of
the audio problems (except for a few minor glitches).

A unix stream socket pair is used as a bi-directional pipe replacement
(the pipe code is still included in this commit, but will be removed later),
with the RX and TX buffer sizes carefully tuned to avoid excessive buffering
(= latency) and a deadlock situation between the write() call in ftdm_write()
and the code in misdn_span_run() that needs a minimum amount of data in the
TX buffer, before sending out a PH_DATA_REQ to the mISDN socket
(see misdn_span_run() comments for more details).

The minimum size for pipes is PAGE_SIZE (4k), which is ~500 ms worth of
audio. A socket pair RX/TX buffer size of 3k, seems to hold a maximum
amount of around 500 bytes data in practice, giving us a much lower
maximum latency than a unix pipe. (The socket pair might be replaced by a
custom ring buffer / fifo data structure to get even more fine grained
control of the maximum latency.)

The newly introduced span_start / span_stop callbacks in
ftdm_io_interface_t are used to start / stop the I/O thread. The callback
functions will wait up to 10 seconds for the thread to successfully
start up or shut down (using a mutex + condition var).

NOTE: Using any of the locking ftdm_span_() functions in the I/O will cause
      a deadlock between the I/O thread (trying to lock span->mutex) and the
      thread calling ftdm_start()/_stop() (holding the span->mutex).
      (The I/O thread currently uses direct span member access to avoid this.)

The I/O thread uses the epoll(7) family of functions for event handling.
An epoll context is created on startup and all B-channel sockets are
registered (READ, PRI and ERR). Before entering the event loop,
the I/O thread will send a signal on the condition variable, to
indicate it has completed the startup procedure.

Incoming b-channel and command pipe events are handled by the event loop.
Payload of incoming PH_DATA_IND frames (= audio data) is sent to the
rx_audio_pipe_in end of the b-channel's socket pair and, if enough data is
available, a PH_DATA_REQ of the same size is sent to the b-channel mISDN socket
to transmit audio.

A MISDN_CMD_STOP command on the event pipe will wake up the I/O thread and
cause it to shut down. All b-channels will be unregistered from the epoll context
and the epoll fd closed. The I/O thread terminates itself after signalling the
successfull shutdown on the condition variable.

TODOs:
    - Move D-Channel into I/O thread too

    - Custom FIFO/ring buffer for data (even lower latency)

    - Improve epoll() code (per-channel struct w/ callback, for epfd.data.ptr)

    - Use mISDN DSP for audio (e.g. tone generator, dtmf detector, echo cancel)

    - Use a per-port / span control socket to execute channel commands
      synchronously, or add misdn_commands (queue?) that can be used that way

    - Name I/O threads 'mISDN-%SPAN_NAME%', e.g. 'mISDN-M_BRI1'
      (= add ftdm_thread_set_namef(thread, fmt, ...) / ftdm_thread_set_name(thread, name))

TL;DR: "tweak", solves "booboo" with audio

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
2012-09-11 14:31:27 -04:00
build fix color coding to be OS appropriate 2012-09-11 14:29:58 -04:00
clients/flex The new jquery.tmpl wants tmpl() instead of render() 2011-08-22 16:14:23 +02:00
cmake_modules Initial CMAKE file commit 2009-02-11 02:53:31 +00:00
conf Fixed Cairo's entry in the timezone files 2012-09-11 14:30:50 -04:00
debian Add sound/music debian packaging instructions 2012-09-11 14:30:49 -04:00
docs Update ChangeLog through July 2012. (Hello from Chicago\!) 2012-08-05 21:54:57 -07:00
dtd
freeswitch.xcodeproj cmake updates 2009-02-13 23:33:36 +00:00
fscomm Update a ton of copyright statements to make sure the dates are proper 2012-04-25 17:14:55 -05:00
htdocs add this from CtRiX -- Thanks. 2008-05-14 20:39:43 +00:00
libs ftmod_misdn: Use a per-span I/O thread to handle B-channel data. 2012-09-11 14:31:27 -04:00
patches zrtp tweaks, more coming 2009-12-17 18:33:45 +00:00
scripts Make version output more human-friendly 2012-07-20 07:43:26 +00:00
src revert 2012-09-11 14:31:27 -04:00
support-d we might want this at some point ;-) 2012-02-01 19:37:23 -05:00
w32 FS-4228 --resolve add zrtp support to windows vs2010 build 2012-05-17 08:38:11 -05:00
web add back empty dirs 2010-04-01 21:00:45 -04:00
.gitattributes add .gitattributes 2012-05-28 16:35:00 +00:00
.gitignore FS-4526 --resolve 2012-09-11 14:29:58 -04:00
CMakeLists.txt FSBUILD-192 2009-10-02 14:44:16 +00:00
Freeswitch.2005.unsupported.sln bye bye iax 2010-01-23 20:19:18 +00:00
Freeswitch.2008.express.sln FS-4504 --resolve 2012-08-14 00:24:56 -05:00
Freeswitch.2008.sln FS-4504 vs2008 pro still need express 2012-08-14 00:24:42 -05:00
Freeswitch.2008.sln.debug.bat merge some changes from joshrivers branch 2009-11-18 15:29:19 +00:00
Freeswitch.2008.sln.release.bat rename 2009-11-18 19:42:00 +00:00
Freeswitch.2010.express.sln FS-4504 --resolve 2012-08-14 00:24:56 -05:00
Freeswitch.2010.sln FS-4504 vs2010 add libjpeg download dependency 2012-08-14 00:23:41 -05:00
INSTALL
Makefile.am Fix sed pattern on OS X 2012-09-11 14:30:49 -04:00
README.md initial commit 2012-09-11 14:24:18 -04:00
acinclude.m4 FS-3182: fix mod_dingaling/iksemel/gnutls link error when using newer autotools 2011-03-25 12:17:25 -05:00
bootstrap.sh fix libwebsocket build 2012-09-11 14:29:56 -04:00
cc.sh come to cluecon will ya 2012-07-06 17:54:21 -05:00
cluecon.tmpl fix color coding to be OS appropriate 2012-09-11 14:29:58 -04:00
cluecon2.tmpl fix color coding to be OS appropriate 2012-09-11 14:29:58 -04:00
configure.in stub for mod_html5 2012-09-11 14:29:56 -04:00
devel-bootstrap.sh Changed permissions for devel-bootstrap.sh 2010-10-13 14:18:38 -07:00
erlang.spec ci/centos: add erlang module support files 2012-03-24 05:15:11 +00:00
freeswitch-sounds-en-us-callie.spec fix sox dependancy 2012-05-15 10:18:14 -05:00
freeswitch-sounds-music.spec --resolve FS-4209 2012-05-15 10:20:52 -05:00
freeswitch-sounds-ru-RU-elena.spec centos: rework CentOS spec files 2012-03-24 04:52:58 +00:00
freeswitch.spec lets kick the auto test with a small change here that doesnt really matter 2012-05-14 13:36:16 -05:00
swig_common.i add 2011-10-21 10:15:15 -05:00

README.md

freeswitch

Personal Copy of Freeswitch