Commit 806cf03f authored by Wim Taymans's avatar Wim Taymans

buffer: add memset function

parent a1f6e021
......@@ -1054,6 +1054,47 @@ gst_buffer_memcmp (GstBuffer * buffer, gsize offset, gconstpointer mem,
return res;
}
/**
* gst_buffer_memset:
* @buffer: a #GstBuffer.
* @offset: the offset in @buffer
* @val: the value to set
* @size: the size to set
*
* Fill @buf with @size bytes with @val starting from @offset.
*/
void
gst_buffer_memset (GstBuffer * buffer, gsize offset, guint8 val, gsize size)
{
gsize i, len;
g_return_if_fail (GST_IS_BUFFER (buffer));
g_return_if_fail (gst_buffer_is_writable (buffer));
len = GST_BUFFER_MEM_LEN (buffer);
for (i = 0; i < len && size > 0; i++) {
guint8 *data;
gsize ssize, toset;
GstMemory *mem;
mem = GST_BUFFER_MEM_PTR (buffer, i);
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_WRITE);
if (ssize > offset) {
/* we have enough */
toset = MIN (ssize - offset, size);
memset (data + offset, val, toset);
size -= toset;
offset = 0;
} else {
/* offset past buffer, skip */
offset -= ssize;
}
gst_memory_unmap (mem, data, ssize);
}
}
/**
* gst_buffer_copy_region:
* @parent: a #GstBuffer.
......
......@@ -249,6 +249,8 @@ void gst_buffer_extract (GstBuffer *buffer, gsize offset,
gpointer dest, gsize size);
gint gst_buffer_memcmp (GstBuffer *buffer, gsize offset,
gconstpointer mem, gsize size);
void gst_buffer_memset (GstBuffer *buffer, gsize offset,
guint8 val, gsize size);
gsize gst_buffer_get_size (GstBuffer *buffer);
void gst_buffer_resize (GstBuffer *buffer, gsize offset, gsize size);
......
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