basesrc: take prefix into account when allocating

Take into account the prefix that we received from the allocation query and use
it to allocate and resize a larger buffer.
This commit is contained in:
Wim Taymans 2012-03-14 18:45:55 +01:00
parent f2d81f4c3d
commit 72ac5f5165

View file

@ -1354,10 +1354,24 @@ gst_base_src_default_alloc (GstBaseSrc * src, guint64 offset,
if (priv->pool) {
ret = gst_buffer_pool_acquire_buffer (priv->pool, buffer, NULL);
} else if (size != -1) {
*buffer = gst_buffer_new_allocate (priv->allocator, size, priv->alignment);
if (G_UNLIKELY (*buffer == NULL))
GstMemory *mem;
guint maxsize;
maxsize = size + priv->prefix;
mem = gst_allocator_alloc (priv->allocator, maxsize, priv->alignment);
if (G_UNLIKELY (mem == NULL))
goto alloc_failed;
if (priv->prefix != 0)
gst_memory_resize (mem, priv->prefix, size);
*buffer = gst_buffer_new ();
if (G_UNLIKELY (*buffer == NULL))
goto buffer_failed;
gst_buffer_take_memory (*buffer, -1, mem);
ret = GST_FLOW_OK;
} else {
GST_WARNING_OBJECT (src, "Not trying to alloc %u bytes. Blocksize not set?",
@ -1372,6 +1386,11 @@ alloc_failed:
GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
return GST_FLOW_ERROR;
}
buffer_failed:
{
GST_ERROR_OBJECT (src, "Failed to allocate buffer");
return GST_FLOW_ERROR;
}
}
static GstFlowReturn