来自:http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/index.html
一、开发plugin前的准备工作:
1、 下载plugin模板:
git clonegit://anongit.freedesktop.org/gstreamer/gst-template.git
里面有gst-app应用例子,gst-plugin例子。我们可以通过修改例子来写一个新的插件。
2、 通过make_element工具来写一个plugin模板:
../tools/make_element MyFilter
会生成gstmyfilter.c
and gstmyfilter.h
.
二、编写plugin:
1. 设置plugin 类型信息,在class_init()中设置:
gst_element_class_set_details_simple(gstelement_class,
"Plugin",
"FIXME:Generic",
"FIXME:Generic TemplateElement",
"AUTHOR_NAME AUTHOR_EMAIL");
2. 设置和添加pad:
1) 在class_init()中添加pad template:
gst_element_class_add_pad_template(gstelement_class,
gst_static_pad_template_get(&src_factory));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get(&sink_factory));
2) 在instance_init()中添加pad到 element中:
filter->sinkpad =gst_pad_new_from_static_template (&sink_factory, "sink");
filter->srcpad =gst_pad_new_from_static_template (&src_factory, "src");
3. Plugin 初始化:
plugin_init (GstPlugin * plugin)
4. 设置 pad 的chain function:
gst_pad_set_chain_function(filter->sinkpad,
GST_DEBUG_FUNCPTR(gst_plugin_template_chain));
gst_plugin_template_chain (GstPad * pad, GstObject * parent, GstBuffer *buf)
{
return gst_pad_push(filter->srcpad, buf);
}
5. 设置 pad 的event function:
gst_pad_set_event_function(filter->sinkpad,
GST_DEBUG_FUNCPTR(gst_plugin_template_sink_event));
三、Pad类型:
1、 sometimespads
一些元件在其被创建时不会立刻产生所有它将用到的衬垫。例如在一个Oggdemuxer的元件中可能发生这种情况。这个元件将会读取Ogg流,每当它在Ogg流中检测到一些元数据流时(例如vorbis,theora),它会为每个元数据流创建动态衬垫。同样,它也会在流终止时删除该衬垫。动态衬垫在demuxer这种元件中可以起到很大的作用。
2、 requestpads
元件同样可以拥有请求衬垫(requestpads)。这种衬垫不是自动被创建,而是根据请求被创建的。这在多路复用(multiplexers)类型的元件中有很大的用处。
1. push mode:
elements that have a chain-function set on their sink pad and pushbuffers on their source pad(s). We call this the push-mode because a peerelement will use gst_pad_push () on a srcpad, which will cause our _chain()-function to be called, which in turn causes our element to push out a bufferon the source pad. The initiative to start the dataflow happens somewhereupstream when it pushes out a buffer and all downstream elements get scheduledwhen their _chain ()-functions are called in turn.
2. pull mode:
设置sinkpad 为pullmode,element 创建一个task(调用gst_pad_start_task()创建),循环调用gst_pad_pull_range(sinkPad,offset,size,&buffer);该函数会找到sinkpad对应的upstream的sourcepad,并调用其getrangefunc()函数,前提是对应的sourcepad需要gst_pad_set_getrange_function。
该sinkpad和对应的upstream的sourcepad都叫pullmode.
五、Caps negotiation:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/chapter-negotiation.html
六、Memory allocation:
七、playbin:
播放URL的bin, webkit中的MediaplayerPrivateGstreamer.cpp就是调用这个playbin去播放网页中的音视频。
gst-plugins-base-0.10.30\gst\playback\gstplaybin2.c
第二章 应用开发
1、gst_element_link(src_element,dest_element);
连接srcelment和destelement,也就是连接srcelement 的srcpad和destelement的sinkpad.
2、Gst_bin_add(GstBin * bin, GstElement * element);
添加element到bin中,该bin也可以是一个pipeline.
3、gst_element_query_duration(playbin, GST_FORMAT_TIME, &dur)
查询element的信息
4. gst_element_set_state()/gst_element_get_state().
设置/查询element的状态,会调用到element中的change_state()方法。