Setting up GStreamer and .NET on Windows

GStreamer During the last months I have been working a lot with the GStreamer framework and Mono, running on Linux. The experience has been quite pleasant (mostly) and I really like how GStreamer is designed and its incredible extensibility.

A couple of weeks ago I decided to test GStreamer on Windows, which sounded strange but nonetheless feasible. In fact, the ossbuild project publishes recent GStreamer packages which can be easily installed on Windows and they work perfectly well. Not all plugins are available still, but the core framework works great.

Then I noticed there actually is a .NET binding for GStreamer among the ossbuild packages. Using GStreamer via .NET on Windows? Blasphemy!

Installing GStreamer

First of all, the base GStreamer environment must be installed. On Linux, GStreamer comes nicely packaged in different packages from the distribution repositories, which include groups of plug-ins providing different functionalities. Each package has a different quality level or some kind of difference from a legal viewpoint (they are split into “good”, “bad” and “ugly” packages, based on the spaghetti western movie I guess).

On Windows on the other hand, you get the MSI installer packages provided by ossbuild, which automatically include most plug-ins. The only difference I found is between the GPL and the LGPL installer: most likely, the LGPL installer doesn't include some plug-ins which are licensed under the GPL.

Anyway, once you install the core framework in one of those flavors, you should install the SDK installer as well. Make sure you pick the same license.

You should get a C:\Program Files (x86)\OSSBuild\GStreamer\v0.10.6 folder, which contains a bin sub-folder with the various GStreamer tools (for instance gst-launch that can be used to test GStreamer pipelines from the command line) and a sdk sub-folder which contains the actual bindings and header files.

Header files can be used to compile a C++ application that depends on GStreamer. In our case, we're interested in the .NET bindings that can be found in the sdk\bindings\dotnet directory.

Creating a sample project

In order to use GStreamer in .NET, you'll need to add a reference to the gstreamer-sharp.dll library. The file is usually located here:
C:\Program Files (x86)\OSSBuild\GStreamer\v0.10.6\sdk\bindings\dotnet\gstreamer-sharp.dll

Notice that the directory containing the .NET assembly also contains another native DLL. This library is used as the “glue” connecting the .NET world to the native GStreamer implementation and is needed by the .NET bindings.

In order to include it, simply add it to your project (as any other file) and enable the “Copy to output directory” option. This ensures that the native library is always delivered with your executable and can be loaded by the bindings assembly.

Also ensure that you are building your .NET assembly for x86. Since GStreamer and its bindings are compiled for the x86 architecture, you must force .NET to just-in-time compile your assembly to x86 as well, otherwise loading the native libraries will fail at runtime (since your application could be JITted to x64).

A sample application

In order to get started, let's test the very basic Hello World application first! For instance:

using System;
using Gst;

namespace GStreamerTest {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("Loaded GStreamer {0}.{1}...", Gst.Version.Major, Gst.Version.Minor);

That's it. You should end up with something like:
Loaded GStreamer 0.10...

Have fun with GStreamer! More samples will come when I get to play with the .NET bindings and I find some spare time to write something down...