概述
在 GStreamer 中, 能力协商 Capabilities negotiation (缩写为 Caps negotiation) 是一个决策的过程,用来决定在 GStreamer 管道中数据流采用何种合适的媒体格式。
理想情况下,Capabilities negotiation 将信息从管道中具有信息的那些元素,传输到管道中相对灵活的那部分元素,并受到管道中并不灵活的那部分元素的约束。
基本规则
以下的基本规则需要遵守
- 下游元素建议格式
- 上游元素决定格式
在 caps negotiation 中有四种 queries/events
GST_QUERY_CAPS: 获取可能的 CapsGST_QUERY_ACCEPT_CAPS: 检查 Caps 是否可行GST_EVENT_CAPS: 配置 Caps(下游)GST_EVENT_RECONFIGURE: 通知上游可用的新 Caps
查询 Queries
一个 pad 可以询问其所连接的 pad 它是不是支持某种格式 GstCaps, 这就是 CAPS query。 支持的 caps 列表可用于为数据传输选择合适的 GstCaps。
CAPS 查询以递归方式工作,元素在构建可能的 caps 时应考虑其对等元素。 由于结果 caps 可能非常大,因此可以使用过滤器 capsfilter 来限制 caps。 只有与过滤器匹配的 caps 才会作为结果 caps 返回。 过滤器caps 的顺序的按照调用者的优先顺序给出,并考虑下游元素所返回的 caps。
filter(in)GST_TYPE_CAPS(默认为 NULL):- 用于过滤结果的GstCapscaps(out)GST_TYPE_CAPS(默认 NULL): - 查询到的 Caps 结果
pad 可以询问对等 pad 是否支持给定的 caps 。 它通过 ACCEPT_CAPS 查询来执行此操作, 这个返回的Caps 是固定。 “ACCEPT_CAPS”查询不需要递归地工作,如果具有这些 caps 的后续 CAPS 事件返回成功,它可以简单地返回 TRUE。
caps(in)GST_TYPE_CAPS:- 要检查的GstCaps,它是固定的值result(out)G_TYPE_BOOLEAN(默认 FALSE): - 如果 Caps 被接受 则为 TRUE
事件 Events
当一个媒体格式协商成功,对端的元素就会以 CAPS 事件发送通知, 此 Caps 是固定的
capsGST_TYPE_CAPS: - 协商的GstCaps, 它必须是固定的
操作 Operation
GStreamer’s two scheduling modes, push mode and pull mode, lend themselves to different mechanisms to achieve this goal. As it is more common we describe push mode negotiation first.
Push-mode negotiation
Push-mode negotiation happens when elements want to push buffers and need to decide on the format. This is called downstream negotiation because the upstream element decides the format for the downstream element. This is the most common case.
Negotiation can also happen when a downstream element wants to receive another data format from an upstream element. This is called upstream negotiation.
The basics of negotiation are as follows:
-
GstCaps(see caps) are refcounted before they are pushed as an event to describe the contents of the following buffer. -
An element should reconfigure itself to the new format received as a CAPS event before processing the following buffers. If the data type in the caps event is not acceptable, the element should refuse the event. The element should also refuse the next buffers by returning an appropriate
GST_FLOW_NOT_NEGOTIATEDreturn value from the chain function. -
Downstream elements can request a format change of the stream by sending a RECONFIGURE event upstream. Upstream elements will renegotiate a new format when they receive a RECONFIGURE event.