Commit 7bcc3baf authored by Wim Taymans's avatar Wim Taymans
Browse files

buffer: improve gst_buffer_new_wrapped_full()

Make it possible to wrap all kinds of memory by exposing all properties to
gst_buffer_new_wrapped_full(). This makes it possible to also create writable
memory without a free function or memory with extra padding.
parent d540a5fc
......@@ -607,29 +607,36 @@ no_memory:
/**
* gst_buffer_new_wrapped_full:
* @flags: #GstMemoryFlags
* @data: data to wrap
* @free_func: function to free @data
* @offset: offset in @data of valid data
* @size: size of valid data in @data starting at @offset
* @maxsize: allocated size of @data
* @offset: offset in @data
* @size: size of valid data
* @user_data: user_data
* @notify: called with @user_data when the memory is freed
*
* Creates a new buffer that wraps the given @data. Valid data is set
* to start at @offset and up to @size. If no @free_func is provided,
* buffer memory is marked READONLY.
* Allocate a new buffer that wraps the given memory. @data must point to
* @maxsize of memory, the wrapped buffer will have the region from @offset and
* @size visible.
*
* MT safe.
* When the buffer is destroyed, @notify will be called with @user_data.
*
* The prefix/padding must be filled with 0 if @flags contains
* #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively.
*
* Returns: (transfer full): a new #GstBuffer
*/
GstBuffer *
gst_buffer_new_wrapped_full (gpointer data, GFreeFunc free_func, gsize offset,
gsize size)
gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data,
gsize maxsize, gsize offset, gsize size, gpointer user_data,
GDestroyNotify notify)
{
GstBuffer *newbuf;
newbuf = gst_buffer_new ();
gst_buffer_append_memory (newbuf,
gst_memory_new_wrapped (free_func ? 0 : GST_MEMORY_FLAG_READONLY,
data, offset + size, offset, size, data, free_func));
gst_memory_new_wrapped (flags, data, maxsize, offset, size,
user_data, notify));
return newbuf;
}
......@@ -649,7 +656,7 @@ gst_buffer_new_wrapped_full (gpointer data, GFreeFunc free_func, gsize offset,
GstBuffer *
gst_buffer_new_wrapped (gpointer data, gsize size)
{
return gst_buffer_new_wrapped_full (data, g_free, 0, size);
return gst_buffer_new_wrapped_full (0, data, size, 0, size, data, g_free);
}
/**
......
......@@ -260,7 +260,9 @@ GType gst_buffer_get_type (void);
GstBuffer * gst_buffer_new (void);
GstBuffer * gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
GstAllocationParams * params);
GstBuffer * gst_buffer_new_wrapped_full (gpointer data, GFreeFunc free_func, gsize offset, gsize size);
GstBuffer * gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data, gsize maxsize,
gsize offset, gsize size, gpointer user_data,
GDestroyNotify notify);
GstBuffer * gst_buffer_new_wrapped (gpointer data, gsize size);
/* memory blocks */
......
......@@ -138,7 +138,8 @@ GST_START_TEST (create_events)
ASSERT_CRITICAL (gst_event_set_stream_config_setup_data (event, NULL));
ASSERT_CRITICAL (gst_event_add_stream_config_header (event, NULL));
cd = gst_buffer_new_wrapped_full ((gpointer) "SetMeUpScottie", NULL, 0, 14);
cd = gst_buffer_new_wrapped_full (0, (gpointer) "SetMeUpScottie", 14, 0, 14,
NULL, NULL);
gst_event_set_stream_config_setup_data (event, cd);
gst_buffer_unref (cd);
......@@ -153,11 +154,15 @@ GST_START_TEST (create_events)
event = gst_event_new_stream_config (GST_STREAM_CONFIG_FLAG_NONE);
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 0);
sh1 = gst_buffer_new_wrapped_full ((gpointer) "Strea", NULL, 0, 5);
sh1 =
gst_buffer_new_wrapped_full (0, (gpointer) "Strea", 5, 0, 5, NULL,
NULL);
gst_event_add_stream_config_header (event, sh1);
gst_buffer_unref (sh1);
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 1);
sh2 = gst_buffer_new_wrapped_full ((gpointer) "mHeader", NULL, 0, 7);
sh2 =
gst_buffer_new_wrapped_full (0, (gpointer) "mHeader", 7, 0, 7, NULL,
NULL);
gst_event_add_stream_config_header (event, sh2);
gst_buffer_unref (sh2);
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment