summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-12-24 19:25:52 +0100
committerWim Taymans <wim@metal.(none)>2009-12-24 19:25:52 +0100
commitd7ecbc6ac300feccb17e88a4b3bc7723bb88eb53 (patch)
tree0c052080dddf03ec4e7fd599e347d1169b066f00
parentbb780fdf73546ec5604eb95326682bd9d6192807 (diff)
collectpads: don't keep buffers reffed longer than needed
Make sure we take ownership of the buffer early without increasing its refcount when we go in the collect function. This reduces the amount of copies needed in order to make the buffer writable in most cases.
-rw-r--r--libs/gst/base/gstcollectpads.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c
index 411fb66a55..f9aa1168a4 100644
--- a/libs/gst/base/gstcollectpads.c
+++ b/libs/gst/base/gstcollectpads.c
@@ -1304,13 +1304,12 @@ static GstFlowReturn
gst_collect_pads_chain (GstPad * pad, GstBuffer * buffer)
{
GstCollectData *data;
GstCollectPads *pads;
GstCollectPadsPrivate *priv;
GstFlowReturn ret;
- GstBuffer **buffer_p;
GST_DEBUG ("Got buffer for pad %s:%s", GST_DEBUG_PAD_NAME (pad));
/* some magic to get the managing collect_pads */
GST_OBJECT_LOCK (pad);
data = (GstCollectData *) gst_pad_get_element_private (pad);
@@ -1343,18 +1342,21 @@ gst_collect_pads_chain (GstPad * pad, GstBuffer * buffer)
GST_DEBUG ("Queuing buffer %p for pad %s:%s", buffer,
GST_DEBUG_PAD_NAME (pad));
/* One more pad has data queued */
pads->queuedpads++;
- buffer_p = &data->buffer;
- gst_buffer_replace (buffer_p, buffer);
+ /* take ownership of the buffer */
+ if (data->buffer)
+ gst_buffer_unref (data->buffer);
+ data->buffer = buffer;
+ buffer = NULL;
/* update segment last position if in TIME */
if (G_LIKELY (data->segment.format == GST_FORMAT_TIME)) {
- GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
+ GstClockTime timestamp = GST_BUFFER_TIMESTAMP (data->buffer);
if (GST_CLOCK_TIME_IS_VALID (timestamp))
gst_segment_set_last_stop (&data->segment, GST_FORMAT_TIME, timestamp);
}
/* While we have data queued on this pad try to collect stuff */
@@ -1402,13 +1404,14 @@ gst_collect_pads_chain (GstPad * pad, GstBuffer * buffer)
while (data->buffer != NULL);
unlock_done:
GST_DEBUG ("Pad %s:%s done", GST_DEBUG_PAD_NAME (pad));
GST_OBJECT_UNLOCK (pads);
unref_data (data);
- gst_buffer_unref (buffer);
+ if (buffer)
+ gst_buffer_unref (buffer);
return ret;
pad_removed:
{
GST_WARNING ("%s got removed from collectpads", GST_OBJECT_NAME (pad));
GST_OBJECT_UNLOCK (pad);
@@ -1445,15 +1448,14 @@ unexpected:
ret = GST_FLOW_UNEXPECTED;
goto unlock_done;
}
clipped:
{
GST_DEBUG ("clipped buffer on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
- GST_OBJECT_UNLOCK (pads);
- unref_data (data);
- return GST_FLOW_OK;
+ ret = GST_FLOW_OK;
+ goto unlock_done;
}
error:
{
/* we print the error, the element should post a reasonable error
* message for fatal errors */
GST_DEBUG ("collect failed, reason %d (%s)", ret, gst_flow_get_name (ret));