[SDL_net] designing threaded network I/O

I am working on a voice telephone program using SDL/net/mixer, but have problems deciding on the most efficient design.
I can’t use Bob Pendleton’s net2 library because I’m not using SDL_INIT_VIDEO. I have drafted a pipeline system, where data
is handed from one worker thread to the next, but am worried about potential bottlenecks and the amount of hand tuning
involved.

The program will have essentially two core functions:

  1. buffering audio in, encoding, packetizing and sending to connected clients
  2. buffering incoming packets, decoding, mixing

First I had one thread with a loop checking for and buffering incoming packets, then checking for and sending outgoing
packets. Then I got worried that bottlenecks will occur and split it into two threads, one to send and one to receive. Now I’m
just at a loss.

Does anyone have any suggestions on how best to design this?

Thanks for everyone’s time. Apologies if this is too off-topic?
John
---- Introducing Spymac MailPro: http://www.spymac.com/mailpro/

The program will have essentially two core functions:

  1. buffering audio in, encoding, packetizing and sending to connected clients
  2. buffering incoming packets, decoding, mixing

UT2004 does roughly this, plus physics, 3D graphics, input, and AI in
one thread. Don’t sweat the bottleneck too much. :slight_smile:

Actually, that’s not accurate; the audio mixing is on a seperate thread,
but the net i/o and packet encoding/decoding all happens in one thread,
with just about everything else.

Unless you are designing a server that needs to scale to an insane
amount of connections, threads make this sort of thing really
complicated to implement, and you end up spending a lot of cycles
locking mutexes, etc anyhow.

btw, enet is a network library someone pointed out to me, which is
pretty sweet: http://enet.cubik.org/Features.html

–ryan.

Oh ryan, thank you thank you!
Not only have you saved me from designing a really inefficient system, but you pointed out the perfect library!
You are my hero.

John

On Sun Aug 22 0:19 , ‘Ryan C. Gordon’ sent:

The program will have essentially two core functions:

  1. buffering audio in, encoding, packetizing and sending to connected clients
  2. buffering incoming packets, decoding, mixing

UT2004 does roughly this, plus physics, 3D graphics, input, and AI in
one thread. Don’t sweat the bottleneck too much. :slight_smile:

Actually, that’s not accurate; the audio mixing is on a seperate thread,
but the net i/o and packet encoding/decoding all happens in one thread,
with just about everything else.

Unless you are designing a server that needs to scale to an insane
amount of connections, threads make this sort of thing really
complicated to implement, and you end up spending a lot of cycles
locking mutexes, etc anyhow.

btw, enet is a network library someone pointed out to me, which is
pretty sweet: http://enet.cubik.org/Features.html

–ryan.

---- Introducing Spymac MailPro: http://www.spymac.com/mailpro/

I am working on a voice telephone program using SDL/net/mixer, but have problems deciding on the most efficient design.
I can’t use Bob Pendleton’s net2 library because I’m not using SDL_INIT_VIDEO.

Actaully, it wouldn’t take that much work to make my code work without
using SDL_INIT_VIDEO. Since it uses its own event queue it can be
decoupled from the SDL event queue by modifying only a couple of
routines.

I have drafted a pipeline system, where data
is handed from one worker thread to the next, but am worried about potential bottlenecks and the amount of hand tuning
involved.

The program will have essentially two core functions:

  1. buffering audio in, encoding, packetizing and sending to connected clients
  2. buffering incoming packets, decoding, mixing

First I had one thread with a loop checking for and buffering incoming packets, then checking for and sending outgoing
packets. Then I got worried that bottlenecks will occur and split it into two threads, one to send and one to receive. Now I’m
just at a loss.

Oddly enough, I wrote a telephone when I was working in the R&D lab of
one of the baby bells. So, I’m rather familiar with the problem. I had
to match the precise bandwidth and timing of a real telephone circuit
and do the IO over an ATM network. 'twas fun.

The best solution I found was to use at least two threads per
connection. One thread reads data coming from the remote station,
converts it for play back, and sends it to the sound out put system. The
other thread reads the input from the microphone and sends it down the
line to the remote system.

You need to be really careful with the total latencies. Just the size of
the input and output buffers can cause a significant delay between the
time you say something and the time the person on the other end hears
it.

	Bob Pendleton

P.S. If you are looking for a consultant to help with the project I am
available. With the “Bush Recovery” in full swing the job market sucks
so bad that you need a masters in computer science just to deliver
pizzas. Not that anyone can afford takeout pizza any more. So, I’m not
only available, I’m available cheap.On Fri, 2004-08-20 at 22:53, John Philip wrote:

Does anyone have any suggestions on how best to design this?

Thanks for everyone’s time. Apologies if this is too off-topic?
John
---- Introducing Spymac MailPro: http://www.spymac.com/mailpro/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±-------------------------------------+