1

我是 Gstreamer 的新手。我对插件的 change_state 函数有疑问。正如我在本指南中所读到的: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;
}

我真的不知道我们如何使用parent_class并调用parent_class->change_state 因为在这个元素的 init 函数中:

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被分配给gst_my_filter_change_state。为什么当 element_class->change_state 分配给另一个函数时,我们仍然可以 在gst_my_filter_change_state中调用element_class->change_state 。谢谢!

4

2 回答 2

2

更改gst_my_filter_class_init (GstMyFilterClass *klass)为这样的内容:

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**
}

并在插件顶部附近的某处添加一个static全局变量。GstXyzClass *parent_class;JustGstXyzClass将是您从中继承的元素的类型,例如GstElementClass. 只需查看其他插件源以获取示例。

于 2012-10-27T09:47:40.717 回答
0

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

于 2012-10-27T12:59:57.203 回答