无法使用gstreamer插件中的g_value_set_object()获取gstreamer应用程序中的对象

时间:2013-01-03 06:21:26

标签: gstreamer

我有一个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类型。任何人都可以提出正在发生的事情吗?

1 个答案:

答案 0 :(得分: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); 
}