1、获取创建插件的模板gst-template
http://hi.baidu.com/zhxust/blog/item/8161ab637d89ac6a0d33fa45
.html
方法一: CVS
$cvs-d:pserver:anoncvs@cvs.freedesktop.org/cvs/gstreamerlogin
password:[root的密码]
$cvs -z3-d:pserver:anoncvs@cvs.freedesktop.org:/cvs/gstreamer cogst-template
方法二: GIT
如果没有安装git,则首先安装git:
$sudo apt-get installgit-core
再获取模板:
$git clonegit://anongit.freedesktop.org/gstreamer/gst-template.git
2、进入目录gst-template/gst-plugin/src
$cdgst-template/gst-plugin/src
$../tools/make_elementExampleFilter
产生文件
gstexamplefilter.c gstexamplefilter.h
3、修改Makefile.am文件 (注意:是src目录下的Makefile.am)
$sudo geditMakefile.am
plugin_LTLIBRARIES = libgstexamplefilter.la
libgstexamplefilter_la_SOURCES = gstexamplefilter.c
libgstexamplefilter_la_CFLAGS = $(GST_CFLAGS)
libgstexamplefilter_la_LIBADD = $(GST_LIBS)
libgstexamplefilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstexamplefilter_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = gstexamplefilter.h
总共有七行
4、导入PKG_CONFIG_PATH环境变量,在命令行输入:
$exportPKG_CONFIG_PATH=/usr/lib/pkgconfig
5、进入目录gst-template/gst-plugin,修改文件autogen.sh
进入上一层目录
$cd..
编辑autogen.sh文件:
$sudo geditautogen.sh
如果是通过CVS获取的模板,则修改原来的
srcfile=src/main.c
为新的:
srcfile=src/gstexamplefilter.c
如果是通过GIT获取的模板,则在autogen.sh的开始添加:
srcfile=src/gstexamplefilter.c
6、运行autogen.sh,产生Makefile文件
$./autogen.sh
7、开始安装:
$./configure
$make
$sudo makeinstall
再进入src子目录中
$cd src
用ls -a查询会有.libs目录产生
(注意: .libs 为隐藏目录)
进入.libs
$cd .libs
$ls -a
会发现里面产生了
libgstexamplefilter.la
libgstexamplefilter.so
8、将插件加入到gstreamer库中
把libgstexamplefilter.la
libgstexamplefilter.so
这两个文件拷贝到系统目录中: /usr/lib/gstreamer-0.10
$sudo cp libgstexamplefilter.la/usr/lib/gstreamer-0.10/libgstexamplefilter.la
$sudo cp libgstexamplefilter.so/usr/lib/gstreamer-0.10/libgstexamplefilter.so
如果gstreamer无法扫描到新加入的plugin,可能是因为路径设置不正确(GST_PLUGIN_PATH环境变量)
用gst-inspect命令来查看plugin时,会建立一个cache文件:如在X86上是
$HOME/.gstreamer-0.10/registry.x86_64.bin
如果有新的plugin加入,可能需要先删除这个cache文件,再重新运行gst-inspect,否则不会把新的plugin
扫描到cache中。
几个重要的环境变量:
1:GST_PLUGIN_SCANNER
env = g_getenv("GST_PLUGIN_SCANNER"); //设置gst-plugin_scanner这个命令的路径
2. GST_PLUGIN_PATH
plugin_path = g_getenv ("GST_PLUGIN_PATH");//plugin的搜索路径
g_warning ("External plugin loader failed. Thismost likely means that "
"the plugin loader helper binary was not found or could not be run."
"%s", (g_getenv ("GST_PLUGIN_PATH") != NULL) ?
"If you are running an uninstalled GStreamer setup, you might need"
"to update your gst-uninstalled script so that the "
"GST_PLUGIN_SCANNER environment variable gets set." : "");
3.GST_PLUGIN_SYSTEM_PATH
GST_PLUGIN_SYSTEM_PATH specifies a list ofplugins that are always
loaded by default. If not set, this defaults tothe system-installed
path,and the plugins installed in the user's home directory
plugin_path = g_getenv("GST_PLUGIN_SYSTEM_PATH");
如果这个变量没有设置,default:
plugin_path = g_getenv("GST_PLUGIN_SYSTEM_PATH");
if (plugin_path == NULL){
home_plugins= g_build_filename (g_get_home_dir (),
".gstreamer-" GST_MAJORMINOR, "plugins", NULL);
}
4. GST_REGISTRY_UPDATE(yes or no),是否重新扫描去更新cache内容
update_env = g_getenv("GST_REGISTRY_UPDATE")
do_update =(strcmp (update_env, "no") != 0)
函数调用:
init_post()->gst_update_registry()->ensure_current_registry()->gst_registry_binary_read_cache
->scan_and_update_registry()
->读环境变量GST_PLUGIN_PATH->gst_registry_scan_path_internal()
->读环境变量GST_PLUGIN_SYSTEM_PATH->gst_registry_scan_path_internal() (从目录下去读文件)
检查插件:
$gst-inspect examplefilter
如果显示了插件的信息,那么插件就创建好了
(2) Gst good/ugly/bad库中的plugin的列表
http://gstreamer.freedesktop.org/documentation/plugins.html
关于whitelist和blacklist(黑名单)
在plugin库中,有些plugin的license是blacklist的:
if (strcmp (plugin->desc.license, "BLACKLIST") ==0)
plugin->flags |= GST_PLUGIN_FLAG_BLACKLISTED;
但是BLACKLIST并不是开放给用户设置的,而是gstreamer里面自己使用的。含义是说如果这个plugin
加载失败时,那么就加入到blacklist中,下次不需要去扫描了,用户也不能去使用。
这种plugin在scan时会进入blacklist的pluginlist中,在下次扫描时不会去扫描这些blacklist。
exchange_packets()->read_one()->handle_rx_packet(payloadLength)->plugin_loader_create_blacklist_plugin()
代码:
if (entry != NULL) {
plugin_loader_create_blacklist_plugin (l,entry);//plugin->desc.license = "BLACKLIST";
l->got_plugin_details = TRUE;
}
如果要查看为什么加载plugin会失败:https://bugzilla.gnome.org/show_bug.cgi?id=627102
plugins are blacklisted when there's an error loading them. You cancheck what went wrong by removing your registry(~/.gstreamer-0.10/registry*) and then running:
GST_DEBUG=2,GST_PLUGIN_LOADING:5,GST_REGISTRY:5gst-inspect-0.10
上面这些参数是设置debug系统:
_gst_debug_init()
(3) Gstreamer中的几个命令使用
http://linux.about.com/library/cmd/blcmdl1_gst-inspect.htm
http://www.opensolarisforum.org/man/man1/gst-inspect.html
gst-inspect:
gst-inspect prints information about available GStreamerplugins, information about a particular plugin, or informationabout a particular element.
If no element or plugin argument is specified,gst-inspect prints a list of all plugins and elements. If anelement or plugin argument is specified,gst-inspect prints information about that element orplug-in. If a given argument is valid as either an element or aplugin, gst-inspect treats the argument as an element, bydefault.
OPTIONS
The following options are supported by gst-inspect:
-a, --print-all Print all elements.
--version Print GStreamer version number.
gst-std-options Standard options available for use withmost GStreamer applications. See gst-std-options(5) for moreinformation.
OPERANDS
The following operands are supported:
element Name of an element.
plugin Name of a plugin.
EXAMPLES
Example 1: Displaying Information About a Plugin:
example% gst-inspect alaw Plugin Details: Name: alaw Description: ALaw audio conversion routines Filename: /usr/lib/gstreamer-0.10/libgstalaw.so Version: 0.10.3 License: LGPL Source module: gst-plugins-good Binary package: GStreamer Good Plug-ins source release Origin URL: Unknown package origin alawdec: A Law audio decoder alawenc: A Law audio encoder 2 features: +-- 2 elements
gst-launch:
gst-launch builds and runs basic GStreamer pipelines.
In simple form, a pipeline-description is a list ofelements separated by exclamation marks (!). Properties can beappended to elements, in the form property=value.
For a complete description of possible values forpipeline-description, see the section Pipeline Descriptionbelow or consult the GStreamer documentation.
Please note that gst-launch is primarily a debugging toolfor developers and users. You should not build applications on topof it. For applications, use the gst_parse_launch() function of theGStreamer API as an easy way to construct pipelines from pipelinedescriptions.
OPTIONS
The following options are supported by gst-launch:
-X,--exclude=type1,type2,... Do not outputstatus information of specified type.
-f, --no-fault Do not install a faulthandler.
-o, -output-=file Save XMLrepresentation of pipeline to file, then exit.
-t, --tags Output tags, also known asmetadata.
-T, --trace Print memory allocation trace,if enabled at compile time.
-v, --verbose Output status information andproperty notifications.
--version Print GStreamer version number.
gst-std-options Standard options available for use withmost GStreamer applications. See gst-std-options(5) for moreinformation.
EXTENDED DESCRIPTION
PipelineDescription
A pipeline consists elements and links. Elements can be put intobins of different sorts. Elements, links and bins can be specifiedin a pipeline description in any order.
Elements
elementtype [property1 ...]
Creates an element of type elementtype and sets theproperties.
Properties
property=value ...
Sets the property to the specified value. You can usegst-inspect(1) to find out about properties and allowedvalues of different elements.
Enumeration properties can be set by name, nick or value.
Bins
[bintype.] ( [property1 ...] pipeline-description )
Specifies that a bin of type bintype is created and thegiven properties are set. Every element between the braces is putinto the bin. Please note the dot that has to be used after thebintype. You will almost never need this functionality, itis only really useful for applications using the gst_launch_parse()API with ’bin’ as bintype. That way it is possible to build partialpipelines instead of a full-fledged top-level pipeline.
Links
[[srcelement].[pad1,...]] ! [[sinkelement].[pad1,...]] [[srcelement].[pad1,...]] ! caps ! [[srcelement].[pad1,...]]
Links the element with name srcelement to the elementwith name sinkelement, using the caps specified incaps as a filter. Names can be set on elements with the nameproperty. If the name is omitted, the element that was specifieddirectly in front of or after the link is used. This works acrossbins. If a padname is given, the link is done with these pads. Ifno pad names are given all possibilities are tried and a matchingpad is used. If multiple padnames are given, both sides must havethe same number of pads specified and multiple links are done inthe given order. So the simplest link is a simple exclamation mark,that links the element to the left of it to the element right ofit.
Caps
mimetype [, property[, property ...]]] [; caps[; caps ...]]
Creates a capability with the given mimetype and optionally withgiven properties. The mimetype can be escaped using " or ’. If youwant to chain caps, you can add more caps in the same formatafterwards.
Properties
name[:type]=value in lists and ranges: [type=]value
Sets the requested property in capabilities. The name is analphanumeric value and the type can have the followingcase-insensitive values:
o i or int for integer values or ranges
o f or float for float values or ranges
o 4 or fourcc for FOURCC values
o b, bool, or boolean for boolean values
o s, str, or string for strings
o l or list for lists
If no type was given, the following order is tried: integer,float, boolean, string. Integer values must be parsable bystrtol(), floats by strtod(). FOURCC values may either be integersor strings. Boolean values are (case insensitive) yes, no, true orfalse and may like strings be escaped with " or ’.
Ranges are in this format: [ property, property ] Lists use this format: ( property [, property ...] )
PipelineControl
A pipeline can be controlled by signals. SIGUSR2 will stop thepipeline (GST_STATE_NULL); SIGUSR1 will put it back to play(GST_STATE_PLAYING). By default, the pipeline will start in theplaying state. There are currently no signals defined to go intothe ready or pause (GST_STATE_READY and GST_STATE_PAUSED) stateexpli- citely.
EXAMPLES
The examples below assume that you have the correct pluginsavailable. In general, "sunaudiosink" can be substituted withanother audio output plugin such as "esdsink", "alsasink","osxaudiosink", or "artsdsink". Likewise, "xvimagesink" can besubstituted with "ximagesink", "sdlvideosink", "osxvideosink", or"aasink". Keep in mind though that different sinks might acceptdifferent formats and even the same sink might accept differentformats on different machines, so you might need to add converterelements like audioconvert and audioresample (for audio) orffmpegcolorspace (for video) in front of the sink to make thingswork.
Example 1: Audio Playback
Play the WAV music file "music.wav":
example% gst-launch filesrc location=music.wav ! wavparse ! sunaudiosink
Play the mp3 music file "music.mp3":
example% gst-launch filesrc location=music.mp3 ! flump3dec ! sunaudiosink
Play the Ogg Vorbis file "music.ogg":
example% gst-launch filesrc location=music.ogg ! oggdemux ! vorbisdec ! audioconvert ! sunaudiosink
Play an mp3 file or an http stream using GNOME-VFS:
example% gst-launch gnomevfssrc location=music.mp3 ! flump3dec ! sunaudiosink
example% gst-launch gnomevfssrc location=http://domain.com/music.mp3 ! flump3dec ! sunaudiosink
Use GNOME-VFS to play an mp3 file located on an SMB server:
example% gst-launch gnomevfssrc location=smb://computer/music.mp3 ! flump3dec ! sunaudiosink
Example 2: Video Playback
Play an Ogg video file:
example% gst-launch filesrc location=video.ogg ! oggdemux ! theoradec ! ffmpegcolorspace ! xvimagesink
Example 3: Format Conversion
Convert an mp3 music file to the Ogg Vorbis format:
example% gst-launch filesrc location=music.mp3 ! flump3dec ! audioconvert ! vorbisenc ! oggmux ! filesink location=music.ogg
Convert an mp3 music file to the FLAC format:
example% gst-launch filesrc location=music.mp3 ! flump3dec ! audioconvert ! flacenc ! filesink location=test.flac
Convert a .WAV file to the Ogg Vorbis format:
example% gst-launch filesrc location=music.wav ! wavparse ! audioconvert ! vorbisenc ! oggmux ! filesink location=music.ogg
Example 4: Recording Audio
Record sound from your audio input and encode it into an Oggfile:
example% gst-launch sunaudiosrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=music.ogg
Example 5: Compact Disk (CDDA)
Play track number 3 from compact disc:
example% gst-launch cddasrc track=3 ! sunaudiosink
Play track number 5 from compact disc:
example% gst-launch cdda://5 ! sunaudiosink
Example 6: Diagnostic
Generate a null stream and ignore it:
example% gst-launch fakesrc ! fakesink
Generate a pure tone to test the audio output:
example% gst-launch audiotestsrc ! sunaudiosink
Generate a familiar test pattern to test the video output:
example% gst-launch videotestsrc ! xvimagesink
Generate a familiar test pattern to test the video output:
example% gst-launch videotestsrc ! ximagesink
Example 7: Automatic Linking
You can use the decodebin element to automatically select theright elements to get a working pipeline.
Play any supported audio format:
example% gst-launch filesrc location=musicfile ! decodebin ! sunaudiosink
Play any supported video format with video and audio output.Threads are used automatically.
example% gst-launch filesrc location=videofile ! decodebin name=decoder decoder. ! queue ! audioconvert ! audioresample ! osssink decoder. ! ffmpegcolorspace ! xvimagesink
To make this even easier, you can use the playbin element:
example% gst-launch playbin uri=file:///home/joe/foo.avi
Example 8: Filtered Connections
These examples show how to use filtered capabilities.
Show a test image and use the YUY2 or YV12 video format forthis:
example% gst-launch videotestsrc ! video/x-raw-yuv,format=urcc)YUY2;video/x-raw-yuv,format=urcc)YV12 ! xvimagesink
Record audio and write it to a .wav file. Force usage of signed16 to 32 bit samples and a sample rate between 32kHz and 64KHz:
example% gst-launch sunaudiosrc ! ’audio/x-raw-int,rate=[32000,64000],width=[16,32],depth={16,24,32},signed=(boolean)true’ ! wavenc ! filesink location=recording.wav 更加详细的信息查看: http://gstreamer.freedesktop.org/documentation/