Make a new method to allocate a buffer + memory that takes the allocator and the
alignment as parameters. Provide a macro for the old method but prefer to use
the new method to encourage plugins to negotiate the allocator properly.
GST_BUFFER_MEM_LEN (buffer) = len + 1;
}
-#if 1
+#if 0
/* buffer alignment in bytes - 1
* an alignment of 7 would be the same as malloc() guarantees
*/
{
if (G_LIKELY (_gst_buffer_type == 0)) {
_gst_buffer_type = gst_mini_object_register ("GstBuffer");
+#if 0
#ifdef HAVE_GETPAGESIZE
#ifdef BUFFER_ALIGNMENT_PAGESIZE
_gst_buffer_data_alignment = getpagesize () - 1;
#endif
#endif
+#endif
}
}
for (i = 0; i < len; i++)
gst_memory_unref (GST_BUFFER_MEM_PTR (buffer, i));
+ /* we set msize to 0 when the buffer is part of the memory block */
if (msize)
g_slice_free1 (msize, buffer);
}
}
/**
- * gst_buffer_new_and_alloc:
+ * gst_buffer_new_allocate:
+ * @allocator: the #GstMemoryAllocator to use
* @size: the size in bytes of the new buffer's data.
+ * @align: the alignment of the buffer memory
+ *
+ * Tries to create a newly allocated buffer with data of the given size and
+ * alignment from @allocator. If the requested amount of memory can't be
+ * allocated, NULL will be returned. The allocated buffer memory is not cleared.
+ *
+ * When @allocator is NULL, the default memory allocator will be used.
*
- * Tries to create a newly allocated buffer with data of the given size. If
- * the requested amount of memory can't be allocated, NULL will be returned.
- * The allocated buffer memory is not cleared.
+ * Allocator buffer memory will be aligned to multiples of (@align + 1) bytes.
*
* Note that when @size == 0, the buffer will not have memory associated with it.
*
* be allocated.
*/
GstBuffer *
-gst_buffer_new_and_alloc (guint size)
+gst_buffer_new_allocate (GstMemoryAllocator * allocator, gsize size,
+ gsize align)
{
GstBuffer *newbuf;
GstMemory *mem;
#if 1
if (size > 0) {
- mem = gst_memory_allocator_alloc (NULL, size, _gst_buffer_data_alignment);
+ mem = gst_memory_allocator_alloc (allocator, size, align);
if (G_UNLIKELY (mem == NULL))
goto no_memory;
} else {
/* allocation */
GstBuffer * gst_buffer_new (void);
-GstBuffer * gst_buffer_new_and_alloc (guint size);
+GstBuffer * gst_buffer_new_allocate (GstMemoryAllocator * allocator, gsize maxsize, gsize align);
/* memory blocks */
guint gst_buffer_n_memory (GstBuffer *buffer);
//#define gst_buffer_create_sub(b,o,s) gst_buffer_copy_region(b,GST_BUFFER_COPY_ALL,o,s)
+#define gst_buffer_new_and_alloc(s) gst_buffer_new_allocate(NULL, s, 0)
+
+
#ifndef GST_DISABLE_DEPRECATED
#endif /* not GST_DISABLE_DEPRECATED */
if (len & 1)
goto wrong_length;
- buffer = gst_buffer_new_and_alloc (len / 2);
+ buffer = gst_buffer_new_allocate (NULL, len / 2, 0);
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
for (i = 0; i < len / 2; i++) {
if (G_UNLIKELY (!bclass->fill))
goto no_function;
- buf = gst_buffer_new_and_alloc (size);
+ buf = gst_buffer_new_allocate (NULL, size, 0);
if (G_UNLIKELY (buf == NULL))
goto alloc_failed;
ret = gst_buffer_pool_acquire_buffer (priv->srcpool, out_buf, NULL);
} else {
GST_DEBUG_OBJECT (trans, "doing alloc of size %u", outsize);
- *out_buf = gst_buffer_new_and_alloc (outsize);
+ *out_buf = gst_buffer_new_allocate (NULL, outsize, 0);
}
}
GST_DP_PAYLOAD_BUFFER, NULL);
buffer =
- gst_buffer_new_and_alloc ((guint) GST_DP_HEADER_PAYLOAD_LENGTH (header));
+ gst_buffer_new_allocate (NULL,
+ (guint) GST_DP_HEADER_PAYLOAD_LENGTH (header), 0);
GST_BUFFER_TIMESTAMP (buffer) = GST_DP_HEADER_TIMESTAMP (header);
GST_BUFFER_DURATION (buffer) = GST_DP_HEADER_DURATION (header);
{
GstBuffer *buf;
- buf = gst_buffer_new_and_alloc (src->parentsize);
+ buf = gst_buffer_new_allocate (NULL, src->parentsize, 0);
src->parent = buf;
src->parentoffset = 0;
blocksize = GST_BASE_SRC (src)->blocksize;
/* create the buffer */
- buf = gst_buffer_new_and_alloc (blocksize);
+ buf = gst_buffer_new_allocate (NULL, blocksize, 0);
if (G_UNLIKELY (buf == NULL))
goto alloc_failed;
GstFlowReturn ret = GST_FLOW_OK;
/* allocate the output buffer of the requested size */
- buf = gst_buffer_new_and_alloc (length);
+ buf = gst_buffer_new_allocate (NULL, length, 0);
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length,