Commit b8c1e813 authored by Wim Taymans's avatar Wim Taymans

buffer: add method to compare buffer data

Add method to compare the data in a buffer.
parent 24bb4140
......@@ -1010,6 +1010,52 @@ gst_buffer_extract (GstBuffer * buffer, gsize offset, gpointer dest, gsize size)
}
}
/**
* gst_buffer_memcmp:
* @buffer: a #GstBuffer.
* @offset: the offset in @buffer
* @mem: the memory to compare
* @size: the size to compare
*
* Compare @size bytes starting from @offset in @buffer with the memory in @mem.
*/
gint
gst_buffer_memcmp (GstBuffer * buffer, gsize offset, gconstpointer mem,
gsize size)
{
gsize i, len;
const guint8 *ptr = mem;
gint res = 0;
g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
g_return_val_if_fail (mem != NULL, 0);
len = GST_BUFFER_MEM_LEN (buffer);
for (i = 0; i < len && size > 0 && res == 0; i++) {
guint8 *data;
gsize ssize, tocmp;
GstMemory *mem;
mem = GST_BUFFER_MEM_PTR (buffer, i);
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_READ);
if (ssize > offset) {
/* we have enough */
tocmp = MIN (ssize - offset, size);
res = memcmp (ptr, data + offset, tocmp);
size -= tocmp;
ptr += tocmp;
offset = 0;
} else {
/* offset past buffer, skip */
offset -= ssize;
}
gst_memory_unmap (mem, data, ssize);
}
return res;
}
/**
* gst_buffer_get_caps:
* @buffer: a #GstBuffer.
......
......@@ -294,6 +294,8 @@ void gst_buffer_fill (GstBuffer *buffer, gsize offset,
gconstpointer src, gsize size);
void gst_buffer_extract (GstBuffer *buffer, gsize offset,
gpointer dest, gsize size);
gint gst_buffer_memcmp (GstBuffer *buffer, gsize offset,
gconstpointer mem, 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