Kamaelia for P2P streaming ?

February 11, 2007 at 02:22 PM | categories: python, oldblog | View Comments

There was another post on comp.lang.python which asked essentially:

> I am 3 months old to python and I have done some small projects. I
> want to build a Peer to Peer streaming client

I wrote a reply back to the person directly and cc'd the kamaelia list, but the core of the reply is that the core of this relatively simple in Kamaelia, so I thought it worth posting here. The core of an actual peer looks like this:

Backplane("AUDIO").activate()

Pipeline( TCPClient( source_IP, source_port),
          PublishTo("AUDIO"),
).activate()

def PassOnAudio(): return SubscribeTo("AUDIO")

SimpleServer(protocol=PassOnAudio,port=source_port).run()

Whilst this clearly needs a source, and the core of that looks like this:
from Kamaelia.Audio.PyMedia.Input import Input  as _SoundInput

Backplane("SOURCE").activate()
Pipeline(
    _SoundInput( channels=1, sample_rate=8000, format="S16_LE" ),
    PublishTo("SOURCE"),
).activate()
def ServeSource(): return SubscribeTo("SOURCE")

SimpleServer(protocol=ServeSource,port=source_port).run()

Clearly there's lot's more to this, but that's the basic core you need. You can build QoS, buffering and multiple sources ontop of this.

The original reply is on sourceforge's archive, or will be when the archives update :)

blog comments powered by Disqus