gstreamer:如何将结构作为参数传递给g_object_set()?

时间:2015-09-07 08:45:40

标签: c++ c gobject

大家好,我目前只能将一个属性设置为gstreamer插件,就像休闲一样。

GstElement *source = gst_bin_get_by_name (GST_BIN (m_pu_pipeline), "ue");

g_object_set(G_OBJECT(source), "objectLeftEnabled", settings.m_b_left, NULL);           
g_object_set(G_OBJECT(source), "objectRemovedEnabled", settings.m_b_removed, NULL);

但是我想像休闲一样设置整个结构。

g_object_set (G_OBJECT (source), "lettremoved-settings", settings,  NULL); 

以下是我到目前为止所做的将结构直接设置为gstreamer插件。

struct _LeftRemoved
{
    bool left;
    bool removed;
}; 

//Declaration of copy and free function.
static gpointer lr_copy (gpointer data);
static void lr_free (gpointer data);

G_DEFINE_BOXED_TYPE (_Leftremoved, lettremoved_settings,
                     lr_copy,
                     lr_free);  

//Defination of copy and free.
static gpointer lr_copy (gpointer data)
{
  struct _LeftRemoved *details = (struct _LeftRemoved *)data;
  struct _LeftRemoved *copy = g_new (struct _LeftRemoved, 1);

  // We need to copy 
  copy->left= details->left;
  copy->removed = details->removed;

  g_print("Set Property From Copy left=%d\n",copy->left);
  g_print("Set Property From Copy removed=%d\n",copy->removed);

  return (gpointer) copy;
}


static void lr_free (gpointer data)
{
        //code for free memory.
}

enum ePropertyType
{
   PROP_OBJ_LR
}

static void gst_ivue_class_init (GstIVUEClass * klass)
{  
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;

  gobject_class->set_property = gst_ivue_set_property;
  gobject_class->get_property = gst_ivue_get_property;
  gobject_class->finalize = gst_ivue_finalize;

  GParamSpec *pspec;
  pspec = g_param_spec_boxed ("lettremoved_settings",     "lettremoved_settings", "Left Removed Settings",lettremoved_settings_get_type(), (GParamFlags)G_PARAM_READWRITE);
  g_object_class_install_property (gobject_class, PROP_OBJ_LR, pspec);

}

static void gst_ivue_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
{
   GstIVUE *filter = GST_IVUE (object);

    switch (prop_id)
    {
       case PROP_OBJ_LR:
            g_boxed_copy(lettremoved_settings_get_type(),&value);
            break;
       default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
} 

static void gst_ivue_get_property( GObject* object, guint prop_id, GValue* value, GParamSpec* pspec )
{
     GstIVUE* filter = GST_IVUE (object);
     switch (prop_id) 
     {
         case PROP_OBJ_LR:
             // Also I don't know how to get value
     } 
}

上面的代码运行成功,但它不是我提供的设置值。 例如,如果我将g_object_set()函数称为:

   settings.left=true;
   settings.removed=true;
   g_object_set (G_OBJECT (source), "lettremoved-settings", settings,  NULL); 

然后在复制功能中,此代码将左侧和已删除的默认值设置为false。 在我出错的地方请帮助我。

1 个答案:

答案 0 :(得分:2)

g_object_set和g_object_get是varrag函数。这意味着你可以在一个电话中设置两个:

g_object_set(G_OBJECT(source),
  "objectLeftEnabled", settings.m_b_left,
  "objectRemovedEnabled", settings.m_b_removed,
  NULL);

另外,仅供参考。而不是g_new和手动复制你可以使用g_memdup()。

当你尝试盒装类型时,你是否传过指针?可能是你需要打电话

g_object_set(G_OBJECT(source)," lettremoved-settings",& settings,NULL);