summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-12-24 16:53:15 +0100
committerWim Taymans <wim@metal.(none)>2009-12-24 16:53:15 +0100
commit633e8f4d9f095ea17114b1f56450287c3a56e15f (patch)
treefda50fbcf831c6a7bd8fe37e4c66ac373c271d42
parent4718b7ef09ba5b4c044f2f45160a40d3fd179107 (diff)
collectpads: avoid doing subbuffers when we can
In some cases we can avoid allocating a subbuffer and instead simply ref the buffer. Callers should perform _make_metadata_writable() in all cases now.
-rw-r--r--libs/gst/base/gstcollectpads.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c
index d795612edd..411fb66a55 100644
--- a/libs/gst/base/gstcollectpads.c
+++ b/libs/gst/base/gstcollectpads.c
@@ -929,13 +929,13 @@ gst_collect_pads_read (GstCollectPads * pads, GstCollectData * data,
* @data: the data to use
* @size: the number of bytes to read
*
- * Get a subbuffer of @size bytes from the given pad @data.
+ * Get a buffer of @size bytes from the given pad @data.
*
* This function should be called with @pads LOCK held, such as in the callback.
*
* Since: 0.10.18
*
- * Returns: A sub buffer. The size of the buffer can be less that requested.
+ * Returns: A #GstBuffer. The size of the buffer can be less that requested.
* A return of NULL signals that the pad is end-of-stream.
* Unref the buffer after use.
*
@@ -945,7 +945,7 @@ GstBuffer *
gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
guint size)
{
- guint readsize;
+ guint readsize, bufsize;
GstBuffer *buffer;
g_return_val_if_fail (pads != NULL, NULL);
@@ -956,9 +956,14 @@ gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
if ((buffer = data->buffer) == NULL)
return NULL;
- readsize = MIN (size, GST_BUFFER_SIZE (buffer) - data->pos);
+ bufsize = GST_BUFFER_SIZE (buffer);
+
+ readsize = MIN (size, bufsize - data->pos);
- return gst_buffer_create_sub (buffer, data->pos, readsize);
+ if (data->pos == 0 && readsize == bufsize)
+ return gst_buffer_ref (buffer);
+ else
+ return gst_buffer_create_sub (buffer, data->pos, readsize);
}
/**
@@ -967,14 +972,14 @@ gst_collect_pads_read_buffer (GstCollectPads * pads, GstCollectData * data,
* @data: the data to use
* @size: the number of bytes to read
*
- * Get a subbuffer of @size bytes from the given pad @data. Flushes the amount
+ * Get a buffer of @size bytes from the given pad @data. Flushes the amount
* of read bytes.
*
* This function should be called with @pads LOCK held, such as in the callback.
*
* Since: 0.10.18
*
- * Returns: A sub buffer. The size of the buffer can be less that requested.
+ * Returns: A #GstBuffer. The size of the buffer can be less that requested.
* A return of NULL signals that the pad is end-of-stream.
* Unref the buffer after use.
*