PicoStreamer internals

The trip of stream from the encoder to a listener


 

In this article we follow an mp3 stream packet from the encoder to a listener, showing in a simple manner how Picostreamer works.

Starting from the encoder...

A shoutcast encoder convert the audio signal (from a music file or live mic) to mp3 data, sending it in real time to a shoutcast server.

For PicoStreamer system there are no shoutcast servers. The encoder connect to PicoIcy, thinking that PicoIcy is a shoutcast server.

Usually this connection (encoder->PicoIcy) is estabilshed via localhost (127.0.0.1) interface: this means that no port must be opened in adsl routers or other firewalls.

...travelling into PicoIcy...

Following the shoutcast source protocol, PicoIcy emulates all handshake and check if the source password is the same of the PicoStreamer user.

At this point PicoIcy make a POST http connection to the picosource.cgi script. This is a normal http POST method, like a classic form submit.

This is an example:

01 POST http://free.picostreamer.org/cgi-bin/picosource.cgi?act=source&agent=PI%2fNG061219 HTTP/1.0
02 Host: free.picostreamer.org
03 User-Agent: PicoIcy/NG
04 Connection: close
05 Pico-Streamer-Id: test:password
06 Pico-Streamer-Info: PicoStreamer Powered Radio
07 Pico-Streamer-Source: PicoIcy
08 Pico-Streamer-Source-Ver: 2/NG
09 Pico-Streamer-Bits: 128
10 Pico-Streamer-CType: audio/mpeg
11 Content-Type: application/octet-stream
12 Content-Length: 2147483647
13 
14 [mp3 data]
Line 01 is the POST connection that uses HTTP 1.0 protocol. On line 05 there are user:password auth info. On line 12 there is an huge Content-Lenght that is mandatory for http protocol (live streaming has not content length but the http header must be here).

Starting from line 14 there is the real data stream.

...inside picosource.cgi...

The script picosource.cgi is a Perl script. There are an huge difference between a CGI script and a PHP script. PHP start execution only when all form data is loaded into server. Perl, otherwise, start execution immediately and apache pipe the data through the input stream: it's like a shell pipe "apache_socket_data | perl_script".

At this point picosource.cgi read from STDIN the data as soon as they are available. At given interval, picosource.cgi check if a listener is connected.

If a listener is waiting for data, picosource send data using UDP packets over localhost interface to the port of the registered listener.

...to picoreader.cgi

When a client connect to PicoStreamer, make a simple GET http connection to the script picoreader.cgi.

This script setup and UDP socket and write the port of this socket to a file in the "port" user dir.

Then, wait for packets sent from picosource.cgi and redirects data to the STDOUT to apache that send data to the listener.

From a media player and apache, the picoreader.cgi it's a normal mp3 file download, so there are no particular needs to listen the stream.


 

Questions? Use the forum


 
 
 
99% imageless - ©Vinz486