basesrc: take prefix into account when allocating
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 14 Mar 2012 17:45:55 +0000 (18:45 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Wed, 14 Mar 2012 17:45:55 +0000 (18:45 +0100)
Take into account the prefix that we received from the allocation query and use
it to allocate and resize a larger buffer.

libs/gst/base/gstbasesrc.c

index 1113405..3d2f671 100644 (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