Pages

Tuesday, December 11, 2012

Using GStreamer to Stream All Audio Captured from Soundcard from One PC to Another

Jump to the solution

The Problem

I often work on multiple computers at a time. Additionally, I use headphones the majority of the time. Sometimes I would like to be able to stream all the sound (including system notifications) from one computer to another, allowing me to hear the system notifications from both machines on my headphones. The old-school way to accomplish this means running an audio cable from the output of one PC to the line in on the other. Although this works, the line-in device is usually low quality and noisy. Plus, what if the computers are far away? How about sending the audio digitally over the network? No need for a cable, assuming the computers are already networked!

The Solution - GStreamer

GStreamer is actually an amazing framework that allows you to create all sorts of media pipelines. In my opinion, it is easier to use than ffmpeg once you become familiar with the concepts of how to use it.

What is GStreamer and how does it work?

GStreamer uses a simple concept. You create pipes. Pipes have a source and a sink. A source generates content, and a sink consumes it. You can do fun things with pipes. Imagine that you have a soda fountain that takes in soda water for one source, soda flavoring from another, and spits out into cup sized increments. This process is very similar to the process of taking a video source and an audio source, combining them into a media stream, and then breaking it up in to packets to send it out over the network. Keep the idea of a pipe, with sources and sinks that you can chain together, in mind.

The trickiest part of GStreamer is that each source and each sink has its own set of input types or output types that it can produce or consume. The trick is matching up sinks to sources. If an mp3 encoding element takes in raw audio and spits out an mp3, you must ensure that something that can source raw audio is plugged in one side and something that sinks mp3 audio is plugged in the other. Makes sense, right? It is a little trickier in practice, just because there are so many different formats media can take.