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,µ,&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