0

我有一个 gstreamer 测试应用程序。我的意图是在我的一个 gstreamer 插件中为我的应用程序定义一个结构。但是我遇到了分段错误。

测试应用程序片段:

notify_func(GObject *obj)
{
  GObject *myobj;
  g_object_get(obj, "my-prop", &myobj,NULL);  
}

插件片段:

get_property()
{
  case MY_PROP:
  g_value_set_object(value, obj1->myStructure);
  break;
}

结构 :

struct obj1 {
  MyStructure *myStructure;
  ...
};

但是我从 g_value_set_object 得到分段错误。确切地说,G_IS_OBJECT(obj) 崩溃了。我的 obj1 实例属于 GST_TYPE_ELEMENT 类型。任何人都可以建议正在发生的事情吗?

4

1 回答 1

1

我编写了类似的“示例”Gstreamer 插件和 Gstreamer 应用程序来测试插件。希望它有帮助,也回答你的问题:)

Gstreamer 插件代码:-

头文件:

typedef struct _test
{
    gchar *filename;
    guint width;
    guint height;
}TEST;

struct _GstSample 
{
    GstElement element;
    GstPad *src;
    GstPad *sink;
#ifndef STRUCTURE   
    gchar *filename;
    guint width;
    guint height;
#else
    TEST *test;
#endif  
    gboolean test_arg;
};

C 文件

gst_sample_class_init(GstSampleClass *klass)
{
  ....
  g_object_class_install_property(gobject_class, PROP_TEST,
    g_param_spec_pointer("test", "test", "Structure Testing", G_PARAM_READWRITE));
}

gst_sample_set_property()
{
  ...
  case PROP_TEST:
   sample->test = (TEST *) g_value_get_pointer(value);
   g_print("Struct filename:%s \t width:%u \t height:%u \n", 
        sample->test->filename,
        sample->test->width, 
        sample->test->height);
}

gst_sample_get_property()
{
  ...
  case PROP_TEST:
   g_value_set_pointer(value, sample->test);
   break;
}

Gstreamer 应用程序代码:-

typedef struct _test
{
    gchar *filename;
    guint width;
    guint height;
}TEST;

main()
{
  ...
  TEST test, *test1;

  test.filename = "Structure";
  test.width = 14;
  test.height = 50;
  g_object_set(G_OBJECT(sample), "test", &test, NULL);  
  ...
  g_object_get(G_OBJECT(sample), "test", &test1, NULL);
  g_print("Struct Addr:%p \t filename:%s \t width:%u \t height:%u \n",
           &test1, test1->filename, test1->width, test1->height); 
}
于 2013-01-15T11:56:11.593 回答