How to override handle_message in GstBin?

风格不统一 提交于 2019-12-12 04:21:21

问题


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.


回答1:


Ok, it's

g_object_new(my_bin_get_type(), NULL);

where my_bin_get_type() is provided by G_DEFINE_TYPE.




回答2:


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).



来源:https://stackoverflow.com/questions/42787900/how-to-override-handle-message-in-gstbin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!