Trying to make a subclass:
mybin.h:
#pragma once
#include <gst/gstbin.h>
G_BEGIN_DECLS
G_DECLARE_DERIVABLE_TYPE(MyBin, my_bin, MY, BIN, GstBin)
struct _MyBinClass
{
GstBinClass parent_class;
};
GstElement* my_bin_new(const gchar *name);
G_END_DECLS
mybin.c:
#include "mybin.h"
G_DEFINE_TYPE(MyBin, my_bin, GST_TYPE_BIN)
static void my_bin_init(MyBin *bin)
{
}
static void my_bin_class_init(MyBinClass *class)
{
// virtual function overrides go here
}
GstElement* my_bin_new(const gchar *name)
{
// ???
}
What to write in my_bin_new()
to make the my_bin_class_init()
be called?
I've seen g_object_new()
in the glib docs, but it's not clear what to pass to it. The gstreamer sources call gst_element_factory_make()
, but I can't see how that factory is related to my custom class.
Ok, it's
g_object_new(my_bin_get_type(), NULL);
where my_bin_get_type()
is provided by G_DEFINE_TYPE
.
GObject will take care of calling those class and object initialization functions when needed (object creation). Check GObject documentation to learn about it: https://developer.gnome.org/gobject/stable/chapter-gobject.html
In short, just implement those as you need and GObject will handle it for you. There are a few examples of overriding the function in GStreamer code: https://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/gst/multifile/gstsplitmuxsink.c#n214
If you want an example that is created directly (not registered to be used via gst_element_factory_make
you can check playback elements: https://cgit.freedesktop.org/gstreamer/gst-plugins-base/tree/gst/playback/gstplaysinkvideoconvert.c, they are created directly in playsink element (code is in the same folder as this one).