basetrans: add an option to prefer passthrough

Basetransform attempts to do passthrough mode regardless of the order of
the transform_caps method. Add a method to disable this.
This is needed for elements like capsfilter that want to transform caps
based on the order of the caps property.
This commit is contained in:
Wim Taymans 2012-10-04 11:15:36 +02:00
parent 664f7141be
commit d5b81aba6a
2 changed files with 42 additions and 6 deletions

View file

@ -255,6 +255,7 @@ struct _GstBaseTransformPrivate
GstPadMode pad_mode;
gboolean gap_aware;
gboolean prefer_passthrough;
/* QoS stats */
guint64 processed;
@ -459,6 +460,7 @@ gst_base_transform_init (GstBaseTransform * trans,
priv->cache_caps2 = NULL;
priv->pad_mode = GST_PAD_MODE_NONE;
priv->gap_aware = FALSE;
priv->prefer_passthrough = TRUE;
priv->passthrough = FALSE;
if (bclass->transform == NULL) {
@ -724,12 +726,14 @@ gst_base_transform_query_caps (GstBaseTransform * trans, GstPad * pad,
gst_caps_unref (caps);
caps = temp;
/* Now try if we can put the untransformed downstream caps first */
temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
if (!gst_caps_is_empty (temp)) {
caps = gst_caps_merge (temp, caps);
} else {
gst_caps_unref (temp);
if (trans->priv->prefer_passthrough) {
/* Now try if we can put the untransformed downstream caps first */
temp = gst_caps_intersect_full (peercaps, caps, GST_CAPS_INTERSECT_FIRST);
if (!gst_caps_is_empty (temp)) {
caps = gst_caps_merge (temp, caps);
} else {
gst_caps_unref (temp);
}
}
} else {
gst_caps_unref (caps);
@ -2594,6 +2598,35 @@ gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
GST_OBJECT_UNLOCK (trans);
}
/**
* gst_base_transform_set_prefer_passthrough:
* @trans: a #GstBaseTransform
* @prefer_passthrough: New state
*
* If @prefer_passthrough is %TRUE (the default), @trans will check and
* prefer passthrough caps from the list of caps returned by the
* transform_caps vmethod.
*
* If set to %FALSE, the element must order the caps returned from the
* transform_caps function in such a way that the prefered format is
* first in the list. This can be interesting for transforms that can do
* passthrough transforms but prefer to do something else, like a
* capsfilter.
*
* MT safe.
*/
void
gst_base_transform_set_prefer_passthrough (GstBaseTransform * trans,
gboolean prefer_passthrough)
{
g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));
GST_OBJECT_LOCK (trans);
trans->priv->prefer_passthrough = prefer_passthrough;
GST_DEBUG_OBJECT (trans, "prefer passthrough %d", prefer_passthrough);
GST_OBJECT_UNLOCK (trans);
}
/**
* gst_base_transform_reconfigure_sink:
* @trans: a #GstBaseTransform

View file

@ -283,6 +283,9 @@ gboolean gst_base_transform_is_qos_enabled (GstBaseTransform *trans);
void gst_base_transform_set_gap_aware (GstBaseTransform *trans,
gboolean gap_aware);
void gst_base_transform_set_prefer_passthrough (GstBaseTransform *trans,
gboolean prefer_passthrough);
GstBufferPool * gst_base_transform_get_buffer_pool (GstBaseTransform *trans);
void gst_base_transform_get_allocator (GstBaseTransform *trans,
GstAllocator **allocator,