mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
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.
This commit is contained in:
parent
d540a5fc68
commit
7bcc3baf64
3 changed files with 30 additions and 16 deletions
|
@ -607,29 +607,36 @@ no_memory:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_buffer_new_wrapped_full:
|
* gst_buffer_new_wrapped_full:
|
||||||
|
* @flags: #GstMemoryFlags
|
||||||
* @data: data to wrap
|
* @data: data to wrap
|
||||||
* @free_func: function to free @data
|
* @maxsize: allocated size of @data
|
||||||
* @offset: offset in @data of valid data
|
* @offset: offset in @data
|
||||||
* @size: size of valid data in @data starting at @offset
|
* @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
|
* Allocate a new buffer that wraps the given memory. @data must point to
|
||||||
* to start at @offset and up to @size. If no @free_func is provided,
|
* @maxsize of memory, the wrapped buffer will have the region from @offset and
|
||||||
* buffer memory is marked READONLY.
|
* @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
|
* Returns: (transfer full): a new #GstBuffer
|
||||||
*/
|
*/
|
||||||
GstBuffer *
|
GstBuffer *
|
||||||
gst_buffer_new_wrapped_full (gpointer data, GFreeFunc free_func, gsize offset,
|
gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data,
|
||||||
gsize size)
|
gsize maxsize, gsize offset, gsize size, gpointer user_data,
|
||||||
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
GstBuffer *newbuf;
|
GstBuffer *newbuf;
|
||||||
|
|
||||||
newbuf = gst_buffer_new ();
|
newbuf = gst_buffer_new ();
|
||||||
gst_buffer_append_memory (newbuf,
|
gst_buffer_append_memory (newbuf,
|
||||||
gst_memory_new_wrapped (free_func ? 0 : GST_MEMORY_FLAG_READONLY,
|
gst_memory_new_wrapped (flags, data, maxsize, offset, size,
|
||||||
data, offset + size, offset, size, data, free_func));
|
user_data, notify));
|
||||||
|
|
||||||
return newbuf;
|
return newbuf;
|
||||||
}
|
}
|
||||||
|
@ -649,7 +656,7 @@ gst_buffer_new_wrapped_full (gpointer data, GFreeFunc free_func, gsize offset,
|
||||||
GstBuffer *
|
GstBuffer *
|
||||||
gst_buffer_new_wrapped (gpointer data, gsize size)
|
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 (void);
|
||||||
GstBuffer * gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
|
GstBuffer * gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
|
||||||
GstAllocationParams * params);
|
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);
|
GstBuffer * gst_buffer_new_wrapped (gpointer data, gsize size);
|
||||||
|
|
||||||
/* memory blocks */
|
/* 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_set_stream_config_setup_data (event, NULL));
|
||||||
ASSERT_CRITICAL (gst_event_add_stream_config_header (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_event_set_stream_config_setup_data (event, cd);
|
||||||
gst_buffer_unref (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);
|
event = gst_event_new_stream_config (GST_STREAM_CONFIG_FLAG_NONE);
|
||||||
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 0);
|
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_event_add_stream_config_header (event, sh1);
|
||||||
gst_buffer_unref (sh1);
|
gst_buffer_unref (sh1);
|
||||||
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 1);
|
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_event_add_stream_config_header (event, sh2);
|
||||||
gst_buffer_unref (sh2);
|
gst_buffer_unref (sh2);
|
||||||
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 2);
|
fail_unless_equals_int (gst_event_get_n_stream_config_headers (event), 2);
|
||||||
|
|
Loading…
Reference in a new issue