gstreamer 应用(二)——Element

GStreamer初始化

读版本信息

#include <gst/gst.h>
#include <stdio.h>
int main(int argc,char* argv[])
{
	const gchar *nano_str;
	guint major,minor,micro,nano;
	gst_init(&argc,&argv);
	gst_version(&major,&minor,&micro,&nano);
	if(nano==1)
		nano_str="(CVS)";
	else if(nano==2)
		nano_str="(Prerelease)";
	else
		nano_str="";
	print("This program is linked against GStreamer %d.%d.%d %s\n",major,minor,micro,nano_str);
	print("This program is linked against GStreamer by define %d.%d.%d \n",GST_VERSION_MAJOR,GST_VERSION_MINOR,GST_VERSION_MICRO);
	return 0;
}

在这里插入图片描述
创建一个element
创建一个组件方法是通过函数gst_element_factory_make()。这个函数使用一个已存在的工厂组件名和一个新的组件名来创建组件。
当不再需要一个组件时,使用gst_object_unref()来对它进行解引用。

#include <gst/gst.h>
#include <stdio.h>
int main(int argc,char* argv[])
{
	GstElement *element;
	gst_init(&argc,&argv);
	/*create element*/
	element =gst_element_factory_make("fakesrc","source");
	if(!element)
	{
		g_print("Failed to create element of type 'fakesrc'\n");
		return -1;
	}
	gst_object_unref(GST_OBJECT(element));
	g_print("Failed to create element of type1 'fakesrc'\n");
	return 0;
}
Failed to create element of type1 'fakesrc'

gst_element_factory_make是两个函数的速记。一个GstElement对象由工厂对象创建而来。gst_element_factory_find 就是使用唯一的工厂对象名来访问一个GstElementFactory对象。
gst_element_factory_create使用组件工厂并根据名字创建一个组件。

	GstElementFactory *factory;	
	GstElement *element;
	···
	factory=gst_element_factory_find("fakesrc");
	if(!factory)
	{
		g_print("Failed to find factory of type 'fakesrc'\n");
		return -1;
	}
	element=gst_element_factory_create(factory,"source");
	if(!element)
	{
		g_print("Failed to create element,even though its factory exists!\n");
		return -1;
	}

设置属性

#include <gst/gst.h>
int main(int argc,char* argv[])
{
	GstElementFactory *factory;	
	GstElement *element;
	gchar *name;
	gst_init(&argc,&argv);
	element=gst_element_factory_make("fakesrc","source");
	g_object_get(G_OBJECT(element),"name",&name,NULL);
	g_print("The name of the element is '%s'.\n",name);
	g_free(name);
	gst_object_unref(GST_OBJECT(element));
	return 0;
}
The name of the element is 'source'.

获取信息

#include <gst/gst.h>
int main(int argc,char* argv[])
{
	GstElementFactory *factory;	
	GstElement *element;
	
	gst_init(&argc,&argv);
	factory=gst_element_factory_find("audiotestsrc");
	if(!factory)
	{
		g_print("You don't have the 'audiotestsrc' element installed!\n");
		return -1;	
	}
	g_print("The '%s' element is a member of the category %s.\n""Description : %s\n",gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory)),gst_element_factory_get_klass(factory),gst_element_factory_get_description(factory));
	
	return 0;
}
The 'audiotestsrc' element is a member of the category Source/Audio.
Description : Creates audio test signals of given frequency and volume
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值