天天看點

Gstreamer學習筆記(6):如何建立gstreamer插件?

    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
           

# 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插件完畢。

繼續閱讀