From f3ca3f89f7ef9bf41371e646fa9ccad712c2a8be Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 22 Feb 2012 15:26:05 +0100 Subject: [PATCH] basetransform: improve propose_allocation Always call the propose_allocation method and provide a default implementation that passes the query on in passthrough mode so that subclasses can also call this. Also pass if the transform is in passthrough mode so that the implementation can adjust its algorithm. --- libs/gst/base/gstbasetransform.c | 36 ++++++++++++++++++++++++-------- libs/gst/base/gstbasetransform.h | 9 +++++--- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 9b42d7a770..6e1debf227 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -330,6 +330,8 @@ static gboolean gst_base_transform_acceptcaps_default (GstBaseTransform * trans, GstPadDirection direction, GstCaps * caps); static gboolean gst_base_transform_setcaps (GstBaseTransform * trans, GstPad * pad, GstCaps * caps); +static gboolean gst_base_transform_default_propose_allocation (GstBaseTransform + * trans, gboolean passthrough, GstQuery * query); static gboolean gst_base_transform_query (GstPad * pad, GstObject * parent, GstQuery * query); static gboolean gst_base_transform_default_query (GstBaseTransform * trans, @@ -392,6 +394,8 @@ gst_base_transform_class_init (GstBaseTransformClass * klass) klass->accept_caps = GST_DEBUG_FUNCPTR (gst_base_transform_acceptcaps_default); klass->query = GST_DEBUG_FUNCPTR (gst_base_transform_default_query); + klass->propose_allocation = + GST_DEBUG_FUNCPTR (gst_base_transform_default_propose_allocation); klass->transform_size = GST_DEBUG_FUNCPTR (gst_base_transform_default_transform_size); @@ -807,7 +811,7 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps) * 2) we need to do a transform, we need to get a bufferpool from downstream * and configure it. When upstream does the ALLOCATION query, the * propose_allocation vmethod will be called and we will configure the - * upstream allocator with our porposed values then. + * upstream allocator with our proposed values then. */ /* clear old pool */ @@ -1303,6 +1307,21 @@ failed_configure: } } +static gboolean +gst_base_transform_default_propose_allocation (GstBaseTransform * trans, + gboolean passthrough, GstQuery * query) +{ + gboolean ret; + + if (passthrough) { + GST_DEBUG_OBJECT (trans, "doing passthrough query"); + ret = gst_pad_peer_query (trans->srcpad, query); + } else { + ret = FALSE; + } + return ret; +} + static gboolean gst_base_transform_default_query (GstBaseTransform * trans, GstPadDirection direction, GstQuery * query) @@ -1334,16 +1353,15 @@ gst_base_transform_default_query (GstBaseTransform * trans, passthrough = trans->passthrough; GST_BASE_TRANSFORM_UNLOCK (trans); - GST_DEBUG_OBJECT (trans, "propose allocation values"); + GST_DEBUG_OBJECT (trans, "propose %spassthrough allocation values", + (passthrough ? "" : "non-")); + /* pass the query to the propose_allocation vmethod if any */ - if (G_LIKELY (klass->propose_allocation)) { - ret = klass->propose_allocation (trans, query); - } else if (passthrough) { - GST_DEBUG_OBJECT (trans, "doing passthrough query"); - ret = gst_pad_peer_query (otherpad, query); - } else { + if (G_LIKELY (klass->propose_allocation)) + ret = klass->propose_allocation (trans, passthrough, query); + else ret = FALSE; - } + GST_DEBUG_OBJECT (trans, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret, query); break; diff --git a/libs/gst/base/gstbasetransform.h b/libs/gst/base/gstbasetransform.h index a092ce12fb..af500e49df 100644 --- a/libs/gst/base/gstbasetransform.h +++ b/libs/gst/base/gstbasetransform.h @@ -162,7 +162,9 @@ struct _GstBaseTransform { * query * @propose_allocation: Propose buffer allocation parameters for upstream elements. * This function must be implemented if the element reads or - * writes the buffer content. The default implementation is NULL. + * writes the buffer content. In passthrough mode, the + * default implementation will forward the ALLOCATION query + * downstream. * @decide_allocation: Setup the allocation parameters for allocating output * buffers. The passed in query contains the result of the * downstream allocation query. This function is only called @@ -237,9 +239,10 @@ struct _GstBaseTransformClass { GstQuery *query); /* propose allocation query parameters for input buffers */ - gboolean (*propose_allocation) (GstBaseTransform *trans, GstQuery *query); + gboolean (*propose_allocation) (GstBaseTransform *trans, gboolean passthrough, + GstQuery *query); /* decide allocation query for output buffers */ - gboolean (*decide_allocation) (GstBaseTransform *trans, GstQuery *query); + gboolean (*decide_allocation) (GstBaseTransform *trans, GstQuery *query); /* transform size */ gboolean (*transform_size) (GstBaseTransform *trans,