From 8337ce91aac11ab5819001101de41d7fc1c54d30 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 20 Aug 2008 10:52:09 +0000 Subject: [PATCH] Implement method for reconfiguring basetransform. Original commit message from CVS: * docs/libs/gstreamer-libs-sections.txt: * libs/gst/base/gstbasetransform.c: (gst_base_transform_handle_buffer), (gst_base_transform_getrange), (gst_base_transform_chain), (gst_base_transform_suggest), (gst_base_transform_reconfigure): * libs/gst/base/gstbasetransform.h: Implement method for reconfiguring basetransform. API: GstBaseTransform::gst_base_transform_reconfigure() --- ChangeLog | 11 +++++++ docs/libs/gstreamer-libs-sections.txt | 1 + libs/gst/base/gstbasetransform.c | 43 ++++++++++++++++++++++----- libs/gst/base/gstbasetransform.h | 1 + 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ccb0ea031..8956b7dd50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-08-20 Wim Taymans + + * docs/libs/gstreamer-libs-sections.txt: + * libs/gst/base/gstbasetransform.c: + (gst_base_transform_handle_buffer), (gst_base_transform_getrange), + (gst_base_transform_chain), (gst_base_transform_suggest), + (gst_base_transform_reconfigure): + * libs/gst/base/gstbasetransform.h: + Implement method for reconfiguring basetransform. + API: GstBaseTransform::gst_base_transform_reconfigure() + 2008-08-20 Stefan Kost patch by: Murray Cumming diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 1f08d57820..1efd3a39bf 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -306,6 +306,7 @@ gst_base_transform_set_qos_enabled gst_base_transform_update_qos gst_base_transform_set_gap_aware gst_base_transform_suggest +gst_base_transform_reconfigure GST_BASE_TRANSFORM_SINK_NAME GST_BASE_TRANSFORM_SRC_NAME diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 59576147b9..bd2b9a1176 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -252,6 +252,8 @@ struct _GstBaseTransformPrivate GstCaps *sink_suggest; guint size_suggest; gint suggest_pending; + + gboolean reconfigure; }; static GstElementClass *parent_class = NULL; @@ -1663,11 +1665,27 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf, { GstBaseTransformClass *bclass; GstFlowReturn ret = GST_FLOW_OK; - gboolean want_in_place; + gboolean want_in_place, reconfigure; GstClockTime qostime; + GstCaps *incaps; bclass = GST_BASE_TRANSFORM_GET_CLASS (trans); + if (G_LIKELY ((incaps = GST_BUFFER_CAPS (inbuf)))) { + GST_OBJECT_LOCK (trans); + reconfigure = trans->priv->reconfigure; + trans->priv->reconfigure = FALSE; + GST_OBJECT_UNLOCK (trans); + + if (G_UNLIKELY (reconfigure)) { + /* if we need to reconfigure we pretend a buffer with new caps arrived. This + * will reconfigure the transform with the new output format. We can only + * do this if the buffer actually has caps. */ + if (!gst_base_transform_setcaps (trans->sinkpad, incaps)) + goto not_negotiated; + } + } + if (GST_BUFFER_OFFSET_IS_VALID (inbuf)) GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset %" G_GUINT64_FORMAT, inbuf, GST_BUFFER_SIZE (inbuf), @@ -1820,7 +1838,9 @@ gst_base_transform_getrange (GstPad * pad, guint64 offset, ret = gst_pad_pull_range (trans->sinkpad, offset, length, &inbuf); if (ret == GST_FLOW_OK) { + GST_BASE_TRANSFORM_LOCK (trans); ret = gst_base_transform_handle_buffer (trans, inbuf, buffer); + GST_BASE_TRANSFORM_UNLOCK (trans); } gst_object_unref (trans); @@ -1847,7 +1867,9 @@ gst_base_transform_chain (GstPad * pad, GstBuffer * buffer) } /* protect transform method and concurrent buffer alloc */ + GST_BASE_TRANSFORM_LOCK (trans); ret = gst_base_transform_handle_buffer (trans, buffer, &outbuf); + GST_BASE_TRANSFORM_UNLOCK (trans); /* outbuf can be NULL, this means a dropped buffer, if we have a buffer but * GST_BASE_TRANSFORM_FLOW_DROPPED we will not push either. */ @@ -2249,7 +2271,8 @@ gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware) * @caps: caps to suggest * @size: buffer size to suggest * - * Instructs @trans to suggest new @caps upstream. + * Instructs @trans to suggest new @caps upstream. A copy of @caps will be + * taken. * * Since: 0.10.21 */ @@ -2262,27 +2285,31 @@ gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps, GST_OBJECT_LOCK (trans->sinkpad); if (trans->priv->sink_suggest) gst_caps_unref (trans->priv->sink_suggest); - trans->priv->sink_suggest = gst_caps_copy (caps); + if (caps) + caps = gst_caps_copy (caps); + trans->priv->sink_suggest = caps; trans->priv->size_suggest = size; g_atomic_int_set (&trans->priv->suggest_pending, 1); GST_DEBUG_OBJECT (trans, "new suggest %" GST_PTR_FORMAT, caps); GST_OBJECT_UNLOCK (trans->sinkpad); } -#if 0 /** * gst_base_transform_reconfigure: * @trans: a #GstBaseTransform * * Instructs @trans to renegotiate a new downstream transform on the next - * buffer. - * - * Note: Not yet implemented. + * buffer. This function is typically called after properties on the transform + * were set that influence the output format. * * Since: 0.10.21 */ void gst_base_transform_reconfigure (GstBaseTransform * trans) { + g_return_if_fail (GST_IS_BASE_TRANSFORM (trans)); + + GST_OBJECT_LOCK (trans); + trans->priv->reconfigure = TRUE; + GST_OBJECT_UNLOCK (trans); } -#endif diff --git a/libs/gst/base/gstbasetransform.h b/libs/gst/base/gstbasetransform.h index 5c26d292ff..d5a3d3e10a 100644 --- a/libs/gst/base/gstbasetransform.h +++ b/libs/gst/base/gstbasetransform.h @@ -258,6 +258,7 @@ void gst_base_transform_set_gap_aware (GstBaseTransform *trans, void gst_base_transform_suggest (GstBaseTransform *trans, GstCaps *caps, guint size); +void gst_base_transform_reconfigure (GstBaseTransform *trans); G_END_DECLS #endif /* __GST_BASE_TRANSFORM_H__ */