分析了三个函数,gst_base_transform_getcaps , gst_base_transform_transform_caps, gst_capsfilter_transform_caps 。
static GstCaps *
gst_base_transform_getcaps (GstPad * pad){
otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;//得到sinkpad.
peercaps = gst_pad_peer_get_caps_reffed (otherpad); //即得到本sinkpad的cpas.
if (peercaps) {
//得到sinkpad的tmplate caps.
templ = gst_pad_get_pad_template_caps (otherpad);
//进行相交
temp = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
}
/* then see what we can transform this to */
//可以参考下面的函数解释。
caps = gst_base_transform_transform_caps (trans,
GST_PAD_DIRECTION (otherpad), temp);
/* and filter against the template of this pad */
//如下得到src的tmplate caps.
templ = gst_pad_get_pad_template_caps (pad);
/* We keep the caps sorted like the returned caps */
temp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
caps = temp;
……
return caps;
}
static GstCaps *
gst_base_transform_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps)
{
gint n = gst_caps_get_size (caps);
for (i = 0; i < n; i++) {
GstCaps *nth;
nth = gst_caps_copy_nth (caps, i);
//下面调用的是gst_capsfilter_transform_caps,如果filter_caps跟nth无交集, //那得到的tmp是空。
temp = klass->transform_caps (trans, direction, nth);
gst_caps_merge (ret, temp);
}
return ret;
}
//可以看出只是跟filter_caps做相交,这是可以从外面设置,如:
//g_object_set(capsfilter, "caps", caps0, NULL);
static GstCaps *
gst_capsfilter_transform_caps (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps)
{
ret = gst_caps_intersect (caps, filter_caps);
return ret;
}