buffer: add memset function

This commit is contained in:
Wim Taymans 2011-07-06 16:08:56 +02:00
parent a1f6e02149
commit 806cf03fbc
2 changed files with 43 additions and 0 deletions

View file

@ -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.

View file

@ -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);