gstreamer的功能强大是毋庸置疑的,它采用C语言编程,但是通过gObject,将各插件封装成面向对象编程的工具。那么如何创建gstreamer呢,当然,可以自己手动写,但是,gstreamer有提供一个叫make_element的工具,我们为什么不直接使用这个工具帮助我们生成所需要的插件呢。
1.获取创建插件的模板 gst-template
首先要确定你的PC安装了git,然后执行以下命令即可在当前目录下获取gst-template源码。
git clone git://anongit.freedesktop.org/gstreamer/gst-template.git
2.创建插件模板
进入gst-template/gst-plugin/src目录,执行以下操作
user# cd gst-template/gst-plugin/src/
user# ../tools/make_element template
执行完上面两步之后,在src目录下将会有gsttemplate.c 、gsttemplate.h这两个文件,他们就是生成的插件模板。
3.修改Makefile.am
在src目录下的Makefile.am文件,内容如下:
# Note: plugindir is set in configure
##############################################################################
# TODO: change libgstplugin.la to something else, e.g. libmysomething.la #
##############################################################################
plugin_LTLIBRARIES = libgstplugin.la libgstaudiofilterexample.la
##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
# e.g. libmysomething.la => libmysomething_la_SOURCES #
# libmysomething_la_CFLAGS #
# libmysomething_la_LIBADD #
# libmysomething_la_LDFLAGS #
##############################################################################
## Plugin 1
# sources used to compile this plug-in
libgstplugin_la_SOURCES = gstplugin.c gstplugin.h
# compiler and linker flags used to compile this plugin, set in configure.ac
libgstplugin_la_CFLAGS = $(GST_CFLAGS)
libgstplugin_la_LIBADD = $(GST_LIBS)
libgstplugin_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstplugin_la_LIBTOOLFLAGS = --tag=disable-static
## Plugin 2 (audio filter example)
# sources used to compile this plug-in
libgstaudiofilterexample_la_SOURCES = gstaudiofilter.c
# compiler and linker flags used to compile this plugin, set in configure.ac
libgstaudiofilterexample_la_CFLAGS = $(GST_CFLAGS)
libgstaudiofilterexample_la_LIBADD = $(GST_LIBS)
libgstaudiofilterexample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstaudiofilterexample_la_LIBTOOLFLAGS = --tag=disable-static
# headers we need but don't want installed
noinst_HEADERS = gstplugin.h
从内容可以知道,添加新的插件之后,直接在该Makefile.am添加该插件的内容即可,添加之后的内容如下:
# Note: plugindir is set in configure
##############################################################################
# TODO: change libgstplugin.la to something else, e.g. libmysomething.la #
##############################################################################
plugin_LTLIBRARIES = libgstplugin.la libgstaudiofilterexample.la libgstexample.la
##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
# e.g. libmysomething.la => libmysomething_la_SOURCES #
# libmysomething_la_CFLAGS #
# libmysomething_la_LIBADD #
# libmysomething_la_LDFLAGS #
##############################################################################
## Plugin 1
# sources used to compile this plug-in
libgstplugin_la_SOURCES = gstplugin.c gstplugin.h
# compiler and linker flags used to compile this plugin, set in configure.ac
libgstplugin_la_CFLAGS = $(GST_CFLAGS)
libgstplugin_la_LIBADD = $(GST_LIBS)
libgstplugin_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstplugin_la_LIBTOOLFLAGS = --tag=disable-static
## Plugin 2 (audio filter example)
# sources used to compile this plug-in
libgstaudiofilterexample_la_SOURCES = gstaudiofilter.c
# compiler and linker flags used to compile this plugin, set in configure.ac
libgstaudiofilterexample_la_CFLAGS = $(GST_CFLAGS)
libgstaudiofilterexample_la_LIBADD = $(GST_LIBS)
libgstaudiofilterexample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstaudiofilterexample_la_LIBTOOLFLAGS = --tag=disable-static
## Plugin 3 (test example)
# sources used to compile this plug-in
libgstexample_la_SOURCES = gsttemplate.c
# compiler and linker flags used to compile this plugin, set in configure.ac
libgstexample_la_CFLAGS = $(GST_CFLAGS)
libgstexample_la_LIBADD = $(GST_LIBS)
libgstexample_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstexample_la_LIBTOOLFLAGS = --tag=disable-static
# headers we need but don't want installed
noinst_HEADERS = gstplugin.h
至此,创建gstreamer插件完毕。