Reputation: 99
I am new to Gstreamer. I have a question about change_state function for plugin. As I read in this guide: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/chapter-statemanage-states.html#section-statemanage-filters
static GstStateChangeReturn
gst_my_filter_change_state (GstElement *element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstMyFilter *filter = GST_MY_FILTER (element);
switch (transition) {
**//Downwards state change;**
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
**//upward state change**
}
return ret;
}
I really don't know how we can use parent_class and call parent_class->change_state Because in init function of this element:
gst_my_filter_class_init (GstMyFilterClass *klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
element_class->change_state = gst_my_filter_change_state;**strong text**
}
element_class->change_state was assigned to gst_my_filter_change_state. Why can we still call element_class->change_state in gst_my_filter_change_state when element_class->change_state is assign to another function. Thank you!
Upvotes: 1
Views: 2882
Reputation: 3450
Change gst_my_filter_class_init (GstMyFilterClass *klass)
to something like this:
gst_my_filter_class_init (GstMyFilterClass *klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
parent_class = (GstXyzClass *) g_type_class_peek_parent (klass);
element_class->change_state = gst_my_filter_change_state;**strong text**
}
And add a static
global variable GstXyzClass *parent_class;
somewhere near the top of your plugin. Just GstXyzClass
will be the type of the Element you are inheriting from, e.g. GstElementClass
. Just look at other plugin sources for examples.
Upvotes: 2
Reputation: 99
Thanks for your answer. Actually,this code I quoted from that guide can run normally.But the thing I can not understand is in header file we declare: GstMyFilterClass {GstElementClass parent_class;}
It means GstElementClass is the father class of GstMyFilterClass
but why can we use parent_class in source file of this plugin(.c file)? Sorry for my lacking of knowledge in Gobject , but as I know GstMyFilterClass is a struct and(not class like C++) and the attribute parent_class can not be used in function of plugin(in C++ we can easily use attribute in method of class). And in the gst_my_filter_class_init :
gst_my_filter_class_init (GstMyFilterClass *klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
element_class->change_state = gst_my_filter_change_state;//assign to function pointer state change
}
Does The statement:GstElementClass *element_class = GST_ELEMENT_CLASS (klass); mean we cast GST_ELEMENT_CLASS (klass) to get its parent class(GstElementClass parent_class)? If it is true,so the change_state function pointer of parent_class is not Null. So In
gst_my_filter_change_state (GstElement *element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstMyFilter *filter = GST_MY_FILTER (element);
switch (transition) {
**//Downwards state change;**
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
**//upward state change**
}
return ret;
}
what is GST_ELEMENT_CLASS (parent_class)->change_state (element, transition)? As I know every GstElementClass has a default function change_state but in this situation function change_state has assigned to another pointer function(gst_my_filter_class_init do this assignment) Is it right? Hope to receive your answer soon. Thank you very much
Upvotes: 0