在Gst中创建动态管道(一)

来源:互联网 发布:python 字典的嵌套 编辑:程序博客网 时间:2024/05/06 20:24

Gstreamer是一个灵活的构架,可以将各种不同的“元素”链接进一个管道(pipeline),允许在管道中自由地添加/删除现有的或新的“工具”以支持各种设备、编解码器(codec),甚至一些特殊的深加工设备。为实现这个目标,需要有一些复杂的assemle/negonatate机制用于链接元素。

bin和管道(pipeline

本章引自Gstreamer ApplicationDevelopment Manual
bin
是一个装载元素集合的容器。管道是特殊的bin类型,允许执行其中的所有子元素。由于bin本身是元素子类(subclass),通常可以像控制元素一样控制bin,从而简化应用程序。比如,可以通过改变bin本身的状态改变bin中所有元素的状态。bin还可以转发来自bin中的子元素的总线(bus)消息(例如错误消息,标签消息和EOS消息)。

管道是顶级bin。将它的状态设置为暂停(PAUSED)或播放(PLAYING)时,则数据流启动,媒体处理开始。启动后,管道将在一个单独的线程中运行,直到被停止或数据流结束。

http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/images/simple-player.png3-1:简单的ogg播放器的Gstreamer管道

示例代码

这里有一个来自gstreamer的示例文件:gst base seek example,该文件经LGPL许可。
有两种方法可以创建回放(playback)管道:

手动将元素链接到管道:

例如:make_wav_pipeline()make_vorbis_pipeline()make_mpeg_pipeline()。创建管道需要4个步骤,以make_vorbis_pipeline()为例:

1.    创建管道和元素

GstElement *pipeline,*audio_bin;
GstElement *src, *demux, *decoder, *convert, *audiosink;
GstPad *pad, *seekable;

pipeline =gst_pipeline_new ("app");

src =gst_element_factory_make_or_warn (SOURCE, "src");
demux = gst_element_factory_make_or_warn ("oggdemux","demux");
decoder = gst_element_factory_make_or_warn ("vorbisdec","decoder");
convert = gst_element_factory_make_or_warn ("audioconvert","convert");
audiosink = gst_element_factory_make_or_warn (ASINK, "sink");
g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL);

g_object_set(G_OBJECT (src), "location", location, NULL);

audio_bin =gst_bin_new ("a_decoder_bin");

2.    将元素添加到管道

gst_bin_add (GST_BIN(pipeline), src);
gst_bin_add (GST_BIN (pipeline), demux);
gst_bin_add (GST_BIN (audio_bin), decoder);
gst_bin_add (GST_BIN (audio_bin), convert);
gst_bin_add (GST_BIN (audio_bin), audiosink);
gst_bin_add (GST_BIN (pipeline), audio_bin);

3.      链接元素和静态衰减器(static pad

gst_element_link (src,demux);
gst_element_link (decoder, convert);
gst_element_link (convert, audiosink);

4.      设置动态衰减器(dynamic pad)的动态链接(主要针对demuxer

pad =gst_element_get_pad (decoder, "sink");
gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad));
gst_object_unref (pad);
setup_dynamic_link (demux, NULL, gst_element_get_pad (audio_bin,"sink"),
NULL); 


未完继续...

本文译自Moblin.org技术社区,  点击此处,查看原文


               更多内容,到“Moblin技术中国”专区