Stream Pulseaudio output to Shout/Icecast server

Recently I’ve been working on setting up a home theater in my basement with a college student’s budget. This endeavour has lead me to try and come up with a solution to stream music downstairs to my XBox (It’s modified to run linux). Really, the only decent software for this is either Icecast or Shoutcast.

I didn’t want to be locked into a specific piece of software that streams to the *cast server, so I started looking into the feasibility of routing a Pulseaudio sink to broadcast to an *cast server.

Step 1: Setup a streaming server

I started out trying to use the Shoutcast pre-compiled binaries but I was having authentication issues with it - IE, couldn’t get it working. So I moved on to the open-source and friendly Icecast.

Fedora doesn’t have a pre-compiled RPM for Icecast so you’ll have to download and compile the source tarball. Thankfully it’s as simple as doing a

tar -xvf icecast-2.3.2.tar.gz
./configure && make install

This will go ahead and setup the Icecast executables and config files. You will have to edit /etc/icecast.xml to change the default password to connect to the server. Since it defaults to ‘hackme’, it’s well advised to change it and not get hacked. Once it’s configured to your liking, start it with

icecast -c /etc/icecast.xml

You may have to be root depending on your permissions setup.

Step 2: G-Streamer launcher setup

This is where the magic happens. GStreamer supports what’s known as ‘Virtual Piping’, in that you describe the pipe setup in the command line to gstreamer and it makes it happen. The problem with Pulseaudio is that it deals with the raw PCM data being catted to the soundcard (remember, everything in linux is a file) and that Icecast streaming servers deal with compressed MP3s or Ogg Vorbis files, so in our pipe setup we have to transcode the raw pcm data. Here’s a description of the pipe we’re going to setup:

  1. Pull PCM data from Pulseaudio source
  2. Signify that we’re going to transcode the stream
  3. Encode it into Ogg Vorbis
  4. Multiplex (Mux) the stream and metadata back together
  5. Pass it out to a icecast server

So, just jumping ahead, here’s the command that I use to start streaming:

gst-launch pulsesrc device=alsa_output.pci_8086_27d8_alsa_playback_0.monitor ! audioconvert ! vorbisenc ! oggmux ! shout2send mount=/stream.ogg port=8000 password=hackme ip=127.0.0.1

GStreamer has a custom version of man pages that it uses. You can get further information about the following options by issuing a ‘gst-inspect {option}’.

  1. The first parameter to gst-launch signifies we’re looking to start our pipe with a Pulaseaudio source. You will have to specifiy which monitor device you want to stream from. I’m using the default alsa monitor for my system so that I stream anything coming out of the speakers. (This is the part that makes it software ambiguous). Another option is to use a filesrc instead to stream from a single file. A filesrc needs a ‘location=’ directive to signify source the same way we used the ‘device=’ directive to signify source.
  2. We describe the pipe using ‘!’, so we’re passing the output of the pulsesrc to the audio conversion engine to transcode from the raw PCM data to Ogg Vorbis.
  3. Followed by vorbisenc. Again, check the available options with ‘gst-inspect vorbisenc’
  4. Merge the streams with oggmux
  5. And finally send it to a Shout-compatible server with ’shout2send’. This is where we’ll be specifiying the server’s information to stream it. Again, ‘gst-inspect shout2send’ for a complete option listing.
    1. ‘mount=/stream.ogg’ is our actual stream file. This is what you’ll be playing to listen to your stream.
    2. ‘ip=127.0.0.1′ My server is the same computer that will be playing and streaming music. Change this to whatever computer will be streaming. (Note, icecast supports multiple sources so long as you change the mount point for each one)
    3. ‘port=8000′ The port the icecast server listens on, you will only need to change this if you’re behind a firewall or it conflicts with another service you’re running.
    4. And finally ‘password=hackme’. ‘hackme’ is the default server password. Change this to the one you setup in step1.

At this point, if all went well, you should be able to point your music player of choice (WM does not support Ogg Vorbis out of box) and point it to ‘http://{serverip}:8000/stream.ogg’ to listen to your stream.

See my next post about transferring live streams to other sinks.

4 Comments

  • By savvas, June 6, 2009 @ 3:52 pm

    In order to find the correct .monitor file:

    defsink=$(echo `cat ~/.pulse/*\:default-sink`.monitor)
    gst-launch pulsesrc device=$defsink ! audioconvert ! vorbisenc ! oggmux ! shout2send mount=/stream.ogg port=8000 password=hackme ip=127.0.0.1

  • By savvas, June 6, 2009 @ 3:56 pm

    Pardon:
    1. Go to System > Preferences > Sound > Set “Sound playback” as Pulseaudio. Press Close
    2. Execute:
    defsinkfile=$(echo `cat ~/.pulse/*\:default-sink`.monitor)
    gst-launch pulsesrc device=$defsinkfile ! audioconvert ! vorbisenc ! oggmux ! shout2send mount=/stream.ogg port=$port password=$password ip=localhost

  • By Gaius, October 25, 2009 @ 4:37 pm

    What about Karmic ? New pulseaudio preferences doesn’t give any information about sink/monitor name….and the one with $defsink does not work anymore…

Other Links to this Post

  1. The Elitist’s Lounge » Moving Audio Streams to Different Sink - Pulseaudio — November 3, 2008 @ 1:54 pm

RSS feed for comments on this post.

Leave a comment

WordPress Themes