From 134b1f0eeed0a6d900765829f0885473b7444f41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 10 Aug 2010 20:11:26 +0200 Subject: [PATCH] imagefreeze: Passthrough buffer allocations --- gst/imagefreeze/gstimagefreeze.c | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gst/imagefreeze/gstimagefreeze.c b/gst/imagefreeze/gstimagefreeze.c index bf1b65e39..78ccda032 100644 --- a/gst/imagefreeze/gstimagefreeze.c +++ b/gst/imagefreeze/gstimagefreeze.c @@ -56,6 +56,8 @@ static gboolean gst_image_freeze_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_image_freeze_sink_setcaps (GstPad * pad, GstCaps * caps); static GstCaps *gst_image_freeze_sink_getcaps (GstPad * pad); static gboolean gst_image_freeze_sink_query (GstPad * pad, GstQuery * query); +static GstFlowReturn gst_image_freeze_sink_bufferalloc (GstPad * pad, + guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf); static void gst_image_freeze_src_loop (GstPad * pad); static gboolean gst_image_freeze_src_event (GstPad * pad, GstEvent * event); static gboolean gst_image_freeze_src_query (GstPad * pad, GstQuery * query); @@ -119,6 +121,8 @@ gst_image_freeze_init (GstImageFreeze * self, GstImageFreezeClass * g_class) GST_DEBUG_FUNCPTR (gst_image_freeze_sink_setcaps)); gst_pad_set_getcaps_function (self->sinkpad, GST_DEBUG_FUNCPTR (gst_image_freeze_sink_getcaps)); + gst_pad_set_bufferalloc_function (self->sinkpad, + GST_DEBUG_FUNCPTR (gst_image_freeze_sink_bufferalloc)); gst_element_add_pad (GST_ELEMENT (self), self->sinkpad); self->srcpad = gst_pad_new_from_static_template (&src_pad_template, "src"); @@ -305,6 +309,38 @@ gst_image_freeze_sink_query (GstPad * pad, GstQuery * query) return ret; } +static GstFlowReturn +gst_image_freeze_sink_bufferalloc (GstPad * pad, guint64 offset, guint size, + GstCaps * caps, GstBuffer ** buf) +{ + GstImageFreeze *self = GST_IMAGE_FREEZE (gst_pad_get_parent (pad)); + GstFlowReturn ret; + gboolean do_alloc; + + GST_LOG_OBJECT (pad, "Allocating buffer with offset 0x%" G_GINT64_MODIFIER + "x and size %u with caps: %" GST_PTR_FORMAT, offset, size, caps); + + *buf = NULL; + + GST_OBJECT_LOCK (self); + do_alloc = self->buffer == NULL; + GST_OBJECT_UNLOCK (self); + + if (do_alloc) { + ret = gst_pad_alloc_buffer (self->srcpad, offset, size, caps, buf); + if (G_UNLIKELY (ret != GST_FLOW_OK)) + GST_ERROR_OBJECT (pad, "Allocating buffer failed: %s", + gst_flow_get_name (ret)); + } else { + /* In this case GstPad will allocate a buffer for us */ + ret = GST_FLOW_OK; + } + + gst_object_unref (self); + + return ret; +} + static gboolean gst_image_freeze_convert (GstImageFreeze * self, GstFormat src_format, gint64 src_value, -- 2.34.1