Gstreamer-GstPad

相关连接:https://blog.csdn.net/knowledgebao/article/details/84621238


目录

Includes

Description

Functions


Includes

#include <gst/gst.h>

GstPad — Object contained by elements that allows links to other elements

Description

GstElement is linked to other elements via "pads", which are extremely light-weight generic link points.

Pads have a GstPadDirection, source pads produce data, sink pads consume data消费数据.

Pads are typically created from a GstPadTemplate with gst_pad_new_from_template()/gst_pad_new_from_static_template()  and are then added to a GstElement. This usually happens when the element is created but it can also happen dynamically based on the data that the element is processing or based on the pads that the application requests.

Pads without pad templates can be created with gst_pad_new(), which takes a direction and a name as an argument. If the name is NULL, then a guaranteed unique name will be assigned to it.

GstElement creating a pad will typically use the various gst_pad_set_*_function()(for example: gst_pad_set_event_function/ gst_pad_set_chain_function...) calls to register callbacks for events, queries or dataflow on the pads.

gst_pad_get_parent() will retrieve the GstElement that owns the pad.

After two pads are retrieved from an element by gst_element_get_static_pad(), the pads can be linked with gst_pad_link(). (For quick links, you can also use gst_element_link(), which will make the obvious link for you if it's straightforward简单的.). Pads can be unlinked again with gst_pad_unlink()gst_pad_get_peer() can be used to check what the pad is linked to.

Before dataflow is possible on the pads, they need to be activated with gst_pad_set_active().

gst_pad_query() and gst_pad_peer_query() can be used to query询问 various properties of the pad and the stream.

To send a GstEvent on a pad, use gst_pad_send_event() and gst_pad_push_event(). Some events will be sticky on the pad黏着在pad上, meaning that after they pass on the pad they can be queried later with gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience便利 functions to query the current sticky CAPS event on a pad.

GstElements will use gst_pad_push() and gst_pad_pull_range() to push out or pull in a buffer.

The dataflow, events and queries that happen on a pad can be monitored检测 with probes探索 that can be installed with gst_pad_add_probe()gst_pad_is_blocked() can be used to check if a block probe is installed on the pad. gst_pad_is_blocking() checks if the blocking probe is currently blocking the pad. gst_pad_remove_probe() is used to remove a previously先前 installed probe and unblock blocking probes if any.

Pad have an offset that can be retrieved with gst_pad_get_offset(). This offset will be applied to the running_time of all data passing over the pad. gst_pad_set_offset() can be used to change the offset.

Convenience functions exist to start, pause and stop the task on a pad with gst_pad_start_task()gst_pad_pause_task() and gst_pad_stop_task() respectively分别地.

functions:

gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)

 

//功能:连接在同一个bin下的多个element,通过
gboolean gst_element_link_many (GstElement * element_1, GstElement * element_2, ...)
{
 while (element_2) {
    if (!gst_element_link (element_1, element_2)) {
      res = FALSE;
      break;
    }

    element_1 = element_2;
    element_2 = va_arg (args, GstElement *);
  }
}

//功能:连接2个element
gboolean gst_element_link (GstElement * src, GstElement * dest)
{
  return gst_element_link_pads (src, NULL, dest, NULL);
}
//功能:连接2个element的pad,padname可以为空
gboolean gst_element_link_pads (GstElement * src, const gchar * srcpadname,
    GstElement * dest, const gchar * destpadname)
{
  return gst_element_link_pads_full (src, srcpadname, dest, destpadname,
      GST_PAD_LINK_CHECK_DEFAULT);
}
//功能:连接2个element的pad,padname可以为空,是gst_pad_link_full()的封装
//如果两个padname的parent不同,返回失败。
gboolean gst_element_link_pads_full (GstElement * src, const gchar * srcpadname,
    GstElement * dest, const gchar * destpadname, GstPadLinkCheck flags)
{
  //***
  if (srcpadname && destpadname) {
    gboolean result;

    /* two explicitly specified pads */
    result = pad_link_maybe_ghosting (srcpad, destpad, flags);
  }
  //***
}
//功能:连接二个pad
static gboolean pad_link_maybe_ghosting (GstPad * src, GstPad * sink, GstPadLinkCheck flags)
{
  if (!prepare_link_maybe_ghosting (&src, &sink, &pads_created)) {
    ret = FALSE;
  } else {
    ret = (gst_pad_link_full (src, sink, flags) == GST_PAD_LINK_OK);
  }
}
//功能:连接二个pad,通过指针交换,达到pad互联
GstPadLinkReturn gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
{
  /* get the link functions */
  srcfunc = GST_PAD_LINKFUNC (srcpad);
  sinkfunc = GST_PAD_LINKFUNC (sinkpad);

  if (G_UNLIKELY (srcfunc || sinkfunc)) {
    /* custom link functions, execute them */
    GST_OBJECT_UNLOCK (sinkpad);
    GST_OBJECT_UNLOCK (srcpad);

    if (srcfunc) {
      GstObject *tmpparent;

      ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
      /* this one will call the peer link function */
      result = srcfunc (srcpad, tmpparent, sinkpad);
      RELEASE_PARENT (tmpparent);
    } else if (sinkfunc) {
      GstObject *tmpparent;

      ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
      /* if no source link function, we need to call the sink link
       * function ourselves. */
      result = sinkfunc (sinkpad, tmpparent, srcpad);
      RELEASE_PARENT (tmpparent);
    }
}

参考资料:

https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html

 


如有任何问题,请联系knowledgebao@163.com

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值