[gst-devel] interfaces & elements (mixer+overlay+input etc.)

iain iain at prettypeople.org
Mon Sep 1 04:06:02 CEST 2003


It all sounds interesting.
I do like the sound of it...

I'll only comment on the bit of it that I understand :)

On Thu, 2003-08-28 at 22:47, Ronald Bultje wrote:

> Glib, apparently (unchecked), has a way of creating interfaces, probably
> by means of a class struct without actually defining the object. The
> object, then, does not define a class and these two add up. Benjamin
> knows more about interfaces, I didn't study interfaces & glib too
> deeply, yet. I know them just from Java.

GLib does indeed have interfaces and they are incredibly simple to use,
once you work it out.

Here's a real-life example from everyone's favourite GStreamer-based
sample editor - MARLIN (which, incidently doesn't work at the moment due
to http://bugzilla.gnome.org/show_bug.cgi?id=119297)

First thing you do in setting up a GInterface is you register it in the
get_type function of the object and then you add it to the object

The interface we are creating here is the GTkEditable interface. This
interface controls things to do with text entry, and s used in the
GtkEntry and GtkTextView widgets.
http://developer.gnome.org/doc/API/2.0/gtk/GtkEditable.html for its
functions and methods.

static const GInterfaceInfo editable_info = {
  (GInterfaceInitFunc) editable_init,
  NULL, NULL
};

g_type_add_interface_static (type, GTK_TYPE_EDITABLE, &editable_info);
/* type comes from g_type_register_static */

Then you just need to implement the interface init function where you
override the methods to do what you want, in this case it performs input
validation.

static void
editable_init (GtkEditableClass *iface)
{
   iface->insert_text = validate_input_text;
}

The fun thing about GInterfaces though is that you can cast between
interfaces and objects, just as you would between objects and their
parent objects.

GtkEntry *entry = GTK_ENTRY (editable);
g_return_if_fail (GTK_IS_EDITABLE (entry));

So, if there was a GstMixer interface, you could do

GstElement *volume = gst_element_factory_make ("volume", "volume");
GstMixer *mixer = GST_MIXER (volume); /* mixer is now our GstMixer 
                                         interface */

Hope this helps you understand GLib interfaces, if not, just ask me on
IRC sometime. If GStreamer does get interfaces it would be nice if they
were done with the GLib stuff.

iain
-- 
"Miss Celine Dion sings lovesongs while our cities burn"





More information about the gstreamer-devel mailing list