From 806cf03fbcbce0046331e2e349003e22238ee1a3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 6 Jul 2011 16:08:56 +0200 Subject: [PATCH] buffer: add memset function --- gst/gstbuffer.c | 41 +++++++++++++++++++++++++++++++++++++++++ gst/gstbuffer.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index dbfc27e660..4380f7a384 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -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. diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 18726035fc..cead4c7741 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -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);