Present Perfect


Picture Gallery
Present Perfect

GStreamer, appsink and CRC32

Filed under: GStreamer,Hacking,Python — Thomas @ 10:50 am

10:50 am

Slowly flexing my GStreamer muscles again in preparation for a real application.

Yesterday I wanted something that allowed me to calculate CRC’s of decoded audio files, to be able to calculate the CRC of a ripped file.

There’s a few ways to do this using GStreamer, none of them code-free.

I assume the ‘correct’ way would be to write a filter element that calculates the CRC as buffers come in. In the olden days this would involve a lot of boiler plate code in C, and a small processing function.

Today, in C, this would be easier, since you could probably simply subclass basetransform.

You could write either in Python as well these days.

Then there’s the ‘get data out of GStreamer’ approach. This used to be done using identity and the handoff signal.

The new, approved, API-stable way is to do this using appsink, one of two elements (with a helper library, of which I don’t yet see the point) recently moved to gst-plugins-base.

Using appsink is probably the approach that involves the least code to write. You can set up a pipeline, set it to PLAYING, and just pull buffers in a blocking fashion (which is easier code to write, but harder to slap a GUI on later)

Here’s the example code. You might note that there is an ugly try/except which I suspect is some bad handling inside gst-python or pygtk for errors during signal handling/emission.

It is a deceptively simple way to get data out of a pipeline and processed, and I’m glad we have a guaranteed way of doing this sort of operation now for the many people who want to dip their toes into GStreamer instead of diving in. I do hope they will at least consider the full dive still though.

Side note 1: GStreamer heads are free to share their opinion on what *should* be the correct way for data analysis operations like this. Years of brainwashing still lead me to believe that the answer would be ‘write a filter element’.

Side note 2: I’ve been toying with the idea of making a python class for ‘asynchronous operations’ that would wrap a GObject main loop doing the processing, and implementations can then subclass and implement some simple methods. This would make it easy to attach that operation to a GUI element (for example, a progress bar) automatically, or adapt it into a linear, blocking operation for command line applications. I can’t imagine this would be a novel idea, I’m sure someone else has done this already, anyone know what I’m talking about or have any suggestions ?


  1. mental barrier to adding an ssl exception > mental barrier to making useless comments

    Comment by wingo — 2009-1-7 @ 2:55 pm

  2. What!? Appsink went into base?! What about appsrc? How come I didn’t see it go through http://bugzilla.gnome.org/show_bug.cgi?id=413418 ?!

    Comment by Snark — 2009-1-7 @ 3:09 pm

  3. Hey, I wrote a program to do this, you might be able to use it or steal some code, check out http://blog.paulbetts.org/index.php/2006/10/16/fancy-new-program-gst-music-hash/

    Comment by Paul Betts — 2009-1-7 @ 4:46 pm

  4. Perhaps get a certificate from a CA whose procedures are trusted by the browser developers? When you can get a free single-name SSL certificate that works in all browsers, why use one that pops up the warnings?

    Things might change once CAcert switches to their new root keys, but I see no reason to trust the existing ones.

    Comment by James Henstridge — 2009-1-8 @ 5:38 am

  5. [...] In a previous post, I mentioned looking for some code implementing asynchronous operations that you can then attach a progress bar to. [...]

    Pingback by thomas.apestaart.org » asynchronous task interface — 2009-4-19 @ 11:13 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment