Archive for June, 2009

Python+GTK: Getting the GError Message from a GPointer

June 28, 2009

In extension to the PyGTK FAQ entry “How can I access data returned with a gpointer?”, here’s a little snippet that extracts the GError message string from a GPointer object.

If for example you want to handle the WebKit.WebView load-error signal in a PyGTK application, you get the error description as gobject.GPointer. However, the C Webkit reference says that the parameter is a GError.

The GError C type looks like this:

typedef struct {
  GQuark       domain;
  gint         code;
  gchar       *message;
} GError;

GQuark is just a guint32.

So the gpointer points to a GError structure, and at the 8th byte in that structure there’s a char* with the message. Here’s how this message string can be extracted:

def _on_load_error (self, browser, frame, uri, gerror):
    ptrValue = int( str(gerror)[13:-1], 16 )
    StringPtrType = ctypes.POINTER(ctypes.c_char_p)
    messagePtr = ctypes.cast(ptrValue + 8, StringPtrType)
    messageText = messagePtr[0]
    print "error occurred while loading %s: %s" % (uri, messageText)

In line 3 we define a new ctypes type (StringPtrType) which is equivalent to a char**. In line 4 we create such a char** (messagePtr), and in line 5 this is dereferenced to get the char*, which is then printed.

Now, as this snippet directly accesses memory structures, chances are that any mistake will make the Python interpreter crash. Also, I’m not sure whether this is portable to other Python implementations or to other architectures; so for any real-world use cases, it would be better to change the library to return the error in a proper format instead of a gpointer.

Installing Gnome DVB Daemon on Ubuntu Jaunty

June 3, 2009

In the last few months there have appeared various blog postings on Planet Gnome about a mysterious Gnome DVB Daemon (http://live.gnome.org/DVBDaemon). So I decided to give it a try on a Ubuntu Jaunty system with a DVB-T USB stick. The hardware itself was detected just fine by the kernel, and after some w_scan fiddling Totem also offered live watching; but I wanted to see if there’s something more user-friendly available, mainly for scanning and for EPG.

For the impatient: yes, after finishing the crazy building and installation steps, it looks quite promising.

So, installation time:

Install GStreamer 0.10.23

Install Gnome RTSP Server

Install newer libgee (Jaunty only ships 0.1.3)

Install Gnome DVB Daemon

Install data files etc.

  • sudo apt-get install dvb-utils

Move Totem plugin to correct location (well… at least, on my system Totem doesn’t look in /usr/local/lib/totem/plugins/):

  • sudo cp -r /usr/local/lib/totem/plugins/dvb-daemon/ /usr/lib/totem/plugins/

Fix Totem plugin (here, Totem failed to load the plugin with error message "Non-ASCII character '\xc3' in file /usr/lib/totem/plugins/dvb-daemon/dvb-daemon.py on line 1," etc.):

  • sudo gedit /usr/lib/totem/plugins/dvb-daemon/dvb-daemon.py
  • add this as first line in the file (before the Copyright line):

    # coding=utf8

For running Gnome DVB Daemon, have a look at the User Guide at http://live.gnome.org/DVBDaemon/UserGuide . EPG, scheduled recording, and the Totem plugin (for live viewing, or viewing recordings) should work fine. Basically run gnome-dvb-setup to scan for channels, then run gnome-dvb-control, go to Preferences dialog to set up “groups” (using the channel file saved in gnome-dvb-setup), and that’s it.

Some quirks I noticed so far:

  • when using the plugin for first time after starting Totem, it will try to install a decoder for “private/teletext” but doesn’t find a matching package – that doesn’t seem to do any harm, though.
  • viewing live video in Totem using the plugin often fails with error message “Could not read from resource.” (and if you run totem on console, you can also see a “503 (Service Unavailable)” error message). No idea what causes this.
  • EPG data in gnome-dvb-control is not available for all channels. Maybe it needs some more time to collect data, or maybe DVB signal is too weak. Unfortunately the GUI doesn’t indicate in the station list for which stations it has EPG data available.