Broadcast to Icecast / SHOUTcast with Objective-C, C, or C++

Solution 1:

Comment: It's about time someone makes a SHOUTcast source client for mobile. I've been needing this for a while, but don't have time to build it, so kudos to you. Please make an Android version at some point.

The first thing you should do is download Wireshark.

Start the packet capture, fire up a SHOUTcast server, then fire up a source client, and connect it to the server. Be prepared for the horrifying simplicity of this protocol.

Primary Audio Protocol

  1. Source client connects to SHOUTcast with TCP. Use the port one up from the base port. For instance, if your base port is 8000, your listeners connect on 8000 and you will connect on 8001.
  2. Once connected, the SHOUTcast server won't say anything. Just send the broadcast password, followed by a new CrLf (or \r\n).
  3. If the password is wrong, it will say invalid password or something like that. If it is correct, you're going to get something like this:

    OK2

    icy-caps:11

    Note that each line has CrLf after it, and after these two headers are sent, there are a pair of CrLf.

  4. Now, it is up to the source client to send a bunch of headers: icy-name, icy-genre, icy-pub, icy-br, icy-url, icy-irc, icy-icq, icy-aim, content-type. Send them like this:

    icy-name:My Awesome Station

    Each line should be followed by CrLf, and after you're done sending all of the headers, send a pair of CrLf.

  5. Once this is all done, start sending your stream data! No need to start in any particular spot, just send data. It is up to the clients on the receiving end to sync to the frame. The SHOUTcast server is completely "dumb" to the traffic flowing through it. You can connect with a Telnet client and send a bunch of text if you wanted to.

Updating Metadata

So, you're probably wondering how you send information for the next track and what not. The funny thing is, this is completely out-of-band from the connection where you send audio data.

All you have to do is make a web request to the port base (8000 in our example):

http://yourserver:8000/admin.cgi?pass=yourpassword&mode=updinfo&song=your%20song&url=some_url_goes_here_but_hardly_any_clients_use_it

In case that is difficult to read, these are the parameters:

  • pass
  • mode
  • song
  • url

You'll note that these same parameters, and others, can all be found in the SHOUTcast admin panel.

Solution 2:

I developed shoutcast wrapper native C files along with a sample android app that you can stream from device microphone -> android-icecast-broadcast.

It is captures, encodes pcm audio from mic. and broadcasts ice server.