mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
buffer: add method to compare buffer data
Add method to compare the data in a buffer.
This commit is contained in:
parent
24bb414035
commit
b8c1e81328
2 changed files with 48 additions and 0 deletions
|
@ -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:
|
* gst_buffer_get_caps:
|
||||||
* @buffer: a #GstBuffer.
|
* @buffer: a #GstBuffer.
|
||||||
|
|
|
@ -294,6 +294,8 @@ void gst_buffer_fill (GstBuffer *buffer, gsize offset,
|
||||||
gconstpointer src, gsize size);
|
gconstpointer src, gsize size);
|
||||||
void gst_buffer_extract (GstBuffer *buffer, gsize offset,
|
void gst_buffer_extract (GstBuffer *buffer, gsize offset,
|
||||||
gpointer dest, gsize size);
|
gpointer dest, gsize size);
|
||||||
|
gint gst_buffer_memcmp (GstBuffer *buffer, gsize offset,
|
||||||
|
gconstpointer mem, gsize size);
|
||||||
|
|
||||||
gsize gst_buffer_get_size (GstBuffer *buffer);
|
gsize gst_buffer_get_size (GstBuffer *buffer);
|
||||||
void gst_buffer_resize (GstBuffer *buffer, gsize offset, gsize size);
|
void gst_buffer_resize (GstBuffer *buffer, gsize offset, gsize size);
|
||||||
|
|
Loading…
Reference in a new issue