This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

Originaly posted here: http://article.gmane.org/gmane.comp.video.gstreamer.devel/29012

Here's the step-by-step of reading and understanding GObject-based code. We'll be going over it in roughly the same order as the code execution.

(Anybody having issues/troubles *reading* and understanding GStreamer/GObject code should read this too and then head to a more extensive GObject documentation to understand the finer details)

GType

The trick to understand ANY GObject classes implementation (and what is needed/used) is to realize that everything GObject related starts with a GType.

A GType is *the* identifier/alias for a class. C doesn't have the notion of classes, so GObject offers a system to be able to differentiate classes (and have inheritance, etc... like any other object-oriented system). If inheritance and classes are unknown to you, go have a quick read on wikipedia about object-oriented programming.

For every class, we need a way to be able to get its GType. The GObject way of doing that is to define a macro to get to it: gstvideobalance.h:

#define GST_TYPE_VIDEO_BALANCE (gst_video_balance_get_type())

==> THIS is the entry point to reading any gobject-code. Anything related to a GObject class starts here !. Look at the rest of the macros in that header, they all use GST_TYPE_VIDEO_BALANCE. If you look at other header files in GStreamer core (like gstelement.h, gstbin.h, ....) they all have those macros pointing to a _get_type() function.

In the GStreamer plugin context, when a plugin is read/loaded (see plugin_init at the bottom of gstvideobalance.c) you also just pass along that GType to GStreamer ("hey GStreamer, here's the GType of a GstElement class you should offer to users").

GObject type registration

Let's carry on reading the code, and have a look at _get_type.

gst_video_balance_get_type

The g_type_register_*() line gives the overview:

You can ignore the parts about interfaces for the time being since they're not essential for this, but if you understood what g_type_register does, it's basically the same idea but for interfaces.

GObject class initialization

This is where we will refine the behaviour of our class, i.e. override class-global behaviour (methods, class global properties, ...)

gst_video_balance_class_init

of the properties you exposed.

GObject instance initialization

gst_video_balance_init()

This method (defined in the type registration) will be called whenever a new instance of our class is created. If instance-specific data needs to be allocated/initialized, it should be done here. Don't forget to free any allocated data in the 'finalize' method of your class.

What now ?

This showed the breakdown of how/what code gets called in a GObject class. Hopefully this should help people be able to *read* gstreamer plugins a bit quicker, and help read/understand the GStreamer reference manual.

If you want an example of a video filter that *does* create new buffers, read in the same way the code to gstvideoflip in the same directory. It's a 700 line self-contained file.


2024-10-23 11:37