diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 870313f33b..c1778c7ccc 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -211,7 +211,7 @@ _memory_add (GstBuffer * buffer, GstMemory * mem) 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 */ @@ -233,10 +233,12 @@ _gst_buffer_initialize (void) { 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 } } @@ -421,6 +423,7 @@ _gst_buffer_free (GstBuffer * buffer) 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); } @@ -470,12 +473,18 @@ gst_buffer_new (void) } /** - * 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. If - * the requested amount of memory can't be allocated, NULL will be returned. - * The allocated buffer memory is not cleared. + * 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. + * + * 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. * @@ -485,7 +494,8 @@ gst_buffer_new (void) * be allocated. */ GstBuffer * -gst_buffer_new_and_alloc (guint size) +gst_buffer_new_allocate (GstMemoryAllocator * allocator, gsize size, + gsize align) { GstBuffer *newbuf; GstMemory *mem; @@ -496,7 +506,7 @@ gst_buffer_new_and_alloc (guint size) #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 { diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index dcd5d2e4b0..c11edd279b 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -226,7 +226,7 @@ struct _GstBuffer { /* 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); diff --git a/gst/gstcompat.h b/gst/gstcompat.h index 8d0c457f7d..cba5fc23f4 100644 --- a/gst/gstcompat.h +++ b/gst/gstcompat.h @@ -49,6 +49,9 @@ G_BEGIN_DECLS //#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 */ diff --git a/gst/gstvalue.c b/gst/gstvalue.c index c1fc50a98a..2fb508819f 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -1789,7 +1789,7 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s) 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++) { diff --git a/libs/gst/base/gstbasesrc.c b/libs/gst/base/gstbasesrc.c index d21e7c6504..6b0165cb9e 100644 --- a/libs/gst/base/gstbasesrc.c +++ b/libs/gst/base/gstbasesrc.c @@ -1259,7 +1259,7 @@ gst_base_src_default_create (GstBaseSrc * src, guint64 offset, 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; diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c index 9af756d51e..b8c9d871a2 100644 --- a/libs/gst/base/gstbasetransform.c +++ b/libs/gst/base/gstbasetransform.c @@ -1406,7 +1406,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans, 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); } } diff --git a/libs/gst/dataprotocol/dataprotocol.c b/libs/gst/dataprotocol/dataprotocol.c index 8b32bb8061..e924ea5ed9 100644 --- a/libs/gst/dataprotocol/dataprotocol.c +++ b/libs/gst/dataprotocol/dataprotocol.c @@ -461,7 +461,8 @@ gst_dp_buffer_from_header (guint header_length, const guint8 * header) 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); diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index 27d80043e0..afe05fe4fb 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -460,7 +460,7 @@ gst_fake_src_alloc_parent (GstFakeSrc * src) { 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; diff --git a/plugins/elements/gstfdsrc.c b/plugins/elements/gstfdsrc.c index 008232707e..eea0af8577 100644 --- a/plugins/elements/gstfdsrc.c +++ b/plugins/elements/gstfdsrc.c @@ -442,7 +442,7 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) 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; diff --git a/plugins/elements/gstqueue2.c b/plugins/elements/gstqueue2.c index 0b7ca8cae8..798c17a7ee 100644 --- a/plugins/elements/gstqueue2.c +++ b/plugins/elements/gstqueue2.c @@ -1138,7 +1138,7 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length, 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,