一、比较重要的宏定义:
以下宏定义 在 gstutils.h文件中。
#define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro)\
GST_BOILERPLATE_FULL (type,type_as_function, parent_type, parent_type_macro, \
__GST_DO_NOTHING)
#define GST_BOILERPLATE_FULL(type,type_as_function, parent_type, parent_type_macro, additional_initializations) \
\
static voidtype_as_function ## _base_init (gpointer g_class); \
static voidtype_as_function ## _class_init (type## Class *g_class);\
static voidtype_as_function ## _init (type *object, \
type ## Class *g_class);\
static parent_type## Class *parent_class = NULL; \
static void \
type_as_function## _class_init_trampoline (gpointer g_class, \
gpointer data) \
{ \
parent_class = (parent_type ## Class *) \
g_type_class_peek_parent (g_class); \
type_as_function ## _class_init ((type ##Class *)g_class); \
} \
\
GType \
type_as_function## _get_type (void) \
{ \
/* The typedef for GType may be gulong orgsize, depending on the \
* system and whether the compiler is c++ ornot. The g_once_init_* \
* functions always take a gsize * though ...*/ \
static volatile gsize gonce_data = 0; \
if (g_once_init_enter (&gonce_data)){ \
GType _type; \
_type = gst_type_register_static_full(parent_type_macro, \
g_intern_static_string (#type), \
sizeof (type ## Class), \
type_as_function ## _base_init, \
NULL, /* base_finalize */ \
type_as_function ##_class_init_trampoline, \
NULL, /* class_finalize */ \
NULL, /* class_data */ \
sizeof (type), \
0, /* n_preallocs */ \
(GInstanceInitFunc) type_as_function ##_init, \
NULL, \
(GTypeFlags) 0); \
additional_initializations (_type); \
g_once_init_leave (&gonce_data, (gsize)_type); \
} \
return (GType) gonce_data; \
}
二、以gstudpsrc.c为例:
GST_BOILERPLATE_FULL (GstUDPSrc, gst_udpsrc, GstPushSrc, GST_TYPE_PUSH_SRC, _do_init);
根据上面的宏定义 展开如下:
GST_BOILERPLATE_FULL(GstUDPSrc, gst_udpsrc, GstPushSrc, GST_TYPE_PUSH_SRC, _do_init);
=======================>>>>>>>>>>>>>>>>>>>>>>>>
#defineGST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro,additional_initializations) \
\
static void gst_udpsrc_base_init (gpointer g_class);
static void gst_udpsrc_class_init (GstUDPSrcClass*g_class);
static void gst_udpsrc_init (GstUDPSrc *object, GstUDPSrcClass *g_class);
static GstPushSrcClass *parent_class = NULL; \
static void \
gst_udpsrc_class_init_trampoline(gpointer g_class, \
gpointer data) \
{ \
parent_class = (GstPushSrcClass *) \
g_type_class_peek_parent (g_class); \
gst_udpsrc_class_init ((GstUDPSrcClass*)g_class); \
} \
\
GType \
gst_udpsrc_get_type(void) \
{ \
/* The typedef for GType may be gulong orgsize, depending on the \
* system and whether the compiler is c++ ornot. The g_once_init_* \
* functions always take a gsize * though ...*/ \
static volatile gsize gonce_data = 0; \
if (g_once_init_enter (&gonce_data)){ \
GType _type; \
_type = gst_type_register_static_full(parent_type_macro, \
g_intern_static_string (#type), \ <--- 传入字符串“GstUDPSrc”
sizeof (GstUDPSrcClass), \
gst_udpsrc_base_init, \
NULL, /* base_finalize */ \
gst_udpsrc_class_init_trampoline, \
NULL, /* class_finalize */ \
NULL, /* class_data */ \
sizeof (type), \
0, /* n_preallocs */ \
(GInstanceInitFunc)gst_udpsrc_init, \
NULL, \
(GTypeFlags) 0); \
additional_initializations (_type); \
g_once_init_leave (&gonce_data, (gsize)_type); \
} \
return (GType) gonce_data; \
}
也许您注意到了 “gst_type_register_static_full” 这个函数, 这个函数的实现您可以在 gstutils.c 这个文件里找到,
摘录代码如下:
--------------------------------------------------------------------------
.................
GTypeInfo info;
info.class_size = class_size;
info.base_init = base_init;
info.base_finalize = base_finalize;
info.class_init = class_init;
info.class_finalize = class_finalize;
info.class_data = class_data;
info.instance_size = instance_size;
info.n_preallocs = n_preallocs;
info.instance_init = instance_init;
info.value_table = value_table;
return g_type_register_static (parent_type, type_name, &info, flags);
--------------------------------------
其中调用了 GObject对象系统 中鼎鼎大名的 类的注册函数,详细请参照,GObject对象系统 相关介绍。
继续 看gstudpsrc.c这个文件,文件中依次对刚才注册的函数进行了实现。
void gst_udpsrc_base_init (gpointer g_class) ;
可见gstreamer的代码和glib库是紧密联系着的。今天先分析到这里,有时间继续分析。
要坚持哦。