一、比較重要的宏定義:
以下宏定義 在 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庫是緊密聯繫着的。今天先分析到這裏,有時間繼續分析。
要堅持哦。