GStreamer 基础教程学习 2 - GStreamer概念 (Basic tutorial 2: GStreamer concepts)

https://gstreamer.freedesktop.org/documentation/tutorials/basic/concepts.html?gi-language=c

上一节教程介绍了一个playbin,这一节具体介绍整个管道是如何构建的。 

1. Element Creation 元素的创建

/* Create the elements */
source = gst_element_factory_make ("videotestsrc", "source");
sink = gst_element_factory_make ("autovideosink", "sink");

As seen in this code, new elements can be created with gst_element_factory_make(). The first parameter is the type of element to create (Basic tutorial 14: Handy elements shows a few common types, and Basic tutorial 10: GStreamer tools shows how to obtain the list of all available types). The second parameter is the name we want to give to this particular instance. Naming your elements is useful to retrieve them later if you didn't keep a pointer (and for more meaningful debug output). If you pass NULL for the name, however, GStreamer will provide a unique name for you.

使用gst_element_factory_make()来创建元素(element),两个参数中第一个为创建元素的类型,第二个是创建的元素的名字。使用名字是后续方便根据名字来进行操作。

2. Pipeline creation 管道的创建

/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");

All elements in GStreamer must typically be contained inside a pipeline before they can be used, because it takes care of some clocking and messaging functions. We create the pipeline with gst_pipeline_new().

这里解释了,在GStreamer中所有的元素在使用之前,都必须包含在一个管道中。管道可以管理好时钟和传递消息。创建一个管道使用函数gst_pipeline_new()。

/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
if (gst_element_link (source, sink) != TRUE) {
  g_printerr ("Elements could not be linked.\n");
  gst_object_unref (pipeline);
  return -1;
}

A pipeline is a particular type of bin, which is the element used to contain other elements. Therefore all methods which apply to bins also apply to pipelines. In our case, we call gst_bin_add_many() to add the elements to the pipeline (mind the cast). This function accepts a list of elements to be added, ending with NULL. Individual elements can be added with gst_bin_add().

管道是一种特殊形式的bin, bin是一种用来包含其他元素的元素。 因此对于bin适用的方法同样也适用管道。这里使用gst_bin_add_many()把元素加入到管道(注意这里的类型转换GST_BIN),这个函数使用列表方式一次性添加多个元素,最后使用NULL来结尾。 单个的元素,使用gst_bin_add()来添加。

These elements, however, are not linked with each other yet. For this, we need to use gst_element_link(). Its first parameter is the source, and the second one the destination. The order counts, because links must be established following the data flow (this is, from source elements to sink elements). Keep in mind that only elements residing in the same bin can be linked together, so remember to add them to the pipeline before trying to link them!

添加完元素之后,还需要使用gst_element_link()将他们连接起来。 函数第一个参数为源,第二个参数为目标。需要注意是属于同一个bin的元素才可以进行连接。

3. Properties 属性

/* Modify the source's properties */
g_object_set (source, "pattern", 0, NULL);

Most GStreamer elements have customizable properties: named attributes that can be modified to change the element's behavior (writable properties) or inquired to find out about the element's internal state (readable properties).

Properties are read from with g_object_get() and written to with g_object_set().

g_object_set() accepts a NULL-terminated list of property-name, property-value pairs, so multiple properties can be changed in one go.

g_object_set()接受以NULL结束的参数列表对属性进行设置, 参数列表需要以属性名称,属性值为一组的方式进行设置。也即

属性1名字,属性1值, 属性2名字,属性2值 .... NULL。通过这种可以一次设置多个属性。

GStreamer elements are all a particular kind of GObject, which is the entity offering property facilities. This is why the property handling methods have the g_ prefix.

The line of code above changes the “pattern” property of videotestsrc, which controls the type of test video the element outputs. Try different values!

The names and possible values of all the properties an element exposes can be found using the gst-inspect-1.0 tool described in Basic tutorial 10: GStreamer tools.

一个元素对外显示的属性的名字和可能的值,可以通过工具 gst-inspect-1.0 来进行查询。这个工具非常有用!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值