Wednesday, January 25, 2012

Notes about writing a gstreamer plugin in vala.

Median/max/sobel filters/OpenCL kernels applied to 
Sintel using Intels OCL SDK and a gstreamer plugin.


Vala, as some of you may know, is a "compiler for the GObject type system". This means, vala is providing a high-level language with e.g. literals for (nearly) all features of gobject and glib. Because vala get's translated to C, it easily integrates with existing C code. Vala code can also be used from C (and other languages, most easily using gobject intropsection) too.

Gstreamer is a nice multimedia framework - and component of the GNOME ecosystem, now more related to freedesktop.org - and is also based on gobject/glib. So it is quite obvious to use vala to build gstreamer plugins and elements.

A gstreamer plugin is organized as a plugin, which wraps one or more elements, which provide the actual functionality. Detailed informations on how to write plugins can be found in the plugin writers guide.

But what is needed to write a plugin and elements in vala? And if it's good to do so.

gst_plugin_desc and plugin_init ()
There are two special structures that need to appear in a Gstreamer plugin: A plugin description (namely the Gst.PluginDesc [vala class]) and the plugin_init () function.
The identifiers of these structures (struct and function) need to match those expected by gstreamer. The plugin description identifier needs to be called gst_plugin_desc and the plugin_init() function also needs to have this name.
In vala it is important to place these methods on the toplevel of your file, and not within a namespace, otherwise vala will prefix the resulting C functions with prefix dervied from the namespace. An alternative is to use a CCode attribute for those structures, but why do this if it can be done easier (as described before).
An working example with correctly named plugin description and init function can be found here.

Namespace
Because of the naming you should also put your elements of the plugin within a Gst namespace e.g. namespace Gst.Myplugin. Because this translates to C structures (generated by vala) prefixed by gst_myplugin_… and the gst (or Gst or GST) prefix is needed, because the buildsystem is looking for those symbols and exports them.
Look in the example above or below to see where to put the element and what kind of namespace to use.

Elements: Gst.BaseTransform
It's quite easy to implement a simple filter. This can be done by subclassing Gst.BaseTransform and overriding (so providing an implementation for) a couple of functions. Have a look here to find out what you need to implement. Or here to see an actual working implementation.

gst-template and buildsystem
You can use the plugin template provided by gstreamer but you obviously need to modify the buildsystem to generate c code from the vala files.
Have a look at this Makefile.am.

Packages & Testing
The basic requirements can be met with the following packages:

$ sudo yum install gstreamer-devel \
gstreamer-plugins-base-devel gstreamer-plugins-base-devel-docs \
vala devhelp

Have you finally compiled your sources try the plugin with gst-launch, remember to add the hidden .libs dir to your path:
$GST_PLUGIN_PATH=src/.libs/ gst-launch  videotestsrc ! myelem ! autovideosink

So yes - you can write gstreamer plugins in vala - so what element are you going to write today?

Thursday, January 19, 2012

fontkodo - Searching through a selection of f/loss repositories.



Fontkodo - best experienced with Firefox, but it also works with others - indexes the repositories hosted at
  • git.gnome.org
  • git.kernel.org
  • git.freedesktop.org
  • git.freesmartphone.org
  • code.entropywave.com
  • git.fedorahosted.org
  • pkgs.fedoraproject.org 
so covering spec files, python, vala, c, and java code, and images.The focus is therefor on Fedora, GNOME, and vala related code: To aid finding spec files, vala examples and digging through vapis.

Maybe this is useful for some starters which want to look at real world example code.
Search for vala files using "lang:vala" or pngs with a miracle using "lang:png beefy".
To find specfiles requiring orc and hosted at pkgs.fedoraproject.org try "origin:pfo lang:spec orc".

Monday, January 16, 2012

redis-2.4.6 lands in updates-testing

Redis -a very nice persistent key-value store with knowledge about lists and sets - 2.4 brings some syntax change / new features.
If you are using redis on Fedora 16 you can test 2.4.6 using the updates-testing repo:
# su -c 'yum update --enablerepo=updates-testing redis-2.4.6-1.fc16'
This update also introduces a systemd unit file, which could also get some attention to see if it works like expected.

This is the second sunny day with temperatures just above 0°c.

Friday, January 6, 2012

Spieglein - Sharing public keys via display and webcam (or so)

Sharing (cryptographic) keys is still mandatory in or cryptography landscape.
A nice exmaple is our ~/.ssh/authorized_keys file which contains a list of public ssh keys which are allowed to login.
One way to exchange those keys is using ssh-copy-id.

Another one is using a webcam and some display - like the ones found in laptops or mobile phones (but even white paper works ;)
The principle is quite simple, just QR encode your public key and point the webcam at the screen to get a picture of the QR encoded public key and decode it.
Voila you've got your own copy of the public key. And it's quite hard to intersect photons on their way from the display to the webcam, so your copy can be trusted.

It is as easy as encoding the image
$ bash create_pubkey_qr.sh 

This results in a image like this:

Now, on the receiving computer, run
$ ./look_for_qr.vala
And point the webcam at the surface displaying the QR code in question ...

You might need to install some dependencies using
$ sudo yum install -y vala glib2-devel qrencode \
gstreamer-plugins-bad-free-extras


Just look here for a working example.

Wednesday, January 4, 2012

Kontinuität - And transforming XML into a UI.


Das frohe neue Jahr hat fahrt aufgenommen - es beginnt fröhlich stürmisch mit frischem Wind.

During the holidays I had some time and looked into xsl transforms again.
This time I needed a nice way to build a simple UI for a specific XML document.
My initial intention was to use a visitor pattern to transform the XML document into a corresponding Gtk UI, but then my eyes catched GtkBuilder.
GtkBuilder builds a UI from an XML definition.
And there it is, an ideal case for xslt: XSL ransform allow you to transform an XML document into some other plain-text document, this includes into other XML or - quite common - XHTML documents.

The simple document looked something like this:
<document id="document" title="About something" author="Jane Doe">
  <text id="intro">Hello World.</text>
  <text id="more">This is something like <i>xml-to-gtk</i></text>
</document>

Using this xsl stylesheet and a bit of glue, resulted in a UI looking like this:

 

Not pretty - but - hey - there are also other techniques that take some markup to built UIs, just think of clutter ...