mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
API: gst_adapter_copy() that can reduce the amount of memcpy when getting data from the adapter. Fixes #388201.
Original commit message from CVS: Patch by: David Schleef <ds at schleef dot org> * docs/libs/gstreamer-libs-sections.txt: * libs/gst/base/gstadapter.c: (gst_adapter_copy): * libs/gst/base/gstadapter.h: API: gst_adapter_copy() that can reduce the amount of memcpy when getting data from the adapter. Fixes #388201.
This commit is contained in:
parent
00a8f6ac84
commit
8be2913771
4 changed files with 65 additions and 0 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2007-01-25 Wim Taymans <wim@fluendo.com>
|
||||
|
||||
Patch by: David Schleef <ds at schleef dot org>
|
||||
|
||||
* docs/libs/gstreamer-libs-sections.txt:
|
||||
* libs/gst/base/gstadapter.c: (gst_adapter_copy):
|
||||
* libs/gst/base/gstadapter.h:
|
||||
API: gst_adapter_copy() that can reduce the amount of memcpy when
|
||||
getting data from the adapter. Fixes #388201.
|
||||
|
||||
2007-01-25 Edward Hervey <edward@fluendo.com>
|
||||
|
||||
* gst/gstregistrybinary.c: (gst_registry_binary_read_cache):
|
||||
|
|
|
@ -123,6 +123,7 @@ gst_adapter_new
|
|||
gst_adapter_clear
|
||||
gst_adapter_push
|
||||
gst_adapter_peek
|
||||
gst_adapter_copy
|
||||
gst_adapter_flush
|
||||
gst_adapter_available
|
||||
gst_adapter_available_fast
|
||||
|
|
|
@ -302,6 +302,58 @@ gst_adapter_peek (GstAdapter * adapter, guint size)
|
|||
return adapter->assembled_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_adapter_copy:
|
||||
* @adapter: a #GstAdapter
|
||||
* @dest: the memory where to copy to
|
||||
* @offset: the bytes offset in the adapter to start from
|
||||
* @size: the number of bytes to copy
|
||||
*
|
||||
* Copies @size bytes of data starting at @offset out of the buffers
|
||||
* contained in @GstAdapter into an array @dest provided by the caller.
|
||||
*
|
||||
* The array @dest should be large enough to contain @size bytes.
|
||||
* The user should check that the adapter has (@offset + @size) bytes
|
||||
* available before calling this function.
|
||||
*
|
||||
* Since: 0.10.12
|
||||
*/
|
||||
void
|
||||
gst_adapter_copy (GstAdapter * adapter, guint8 * dest, guint offset, guint size)
|
||||
{
|
||||
GSList *g;
|
||||
int skip;
|
||||
|
||||
g_return_if_fail (GST_IS_ADAPTER (adapter));
|
||||
g_return_if_fail (size > 0);
|
||||
|
||||
/* we don't have enough data, return. This is unlikely
|
||||
* as one usually does an _available() first instead of copying a
|
||||
* random size. */
|
||||
if (G_UNLIKELY (offset + size > adapter->size))
|
||||
return;
|
||||
|
||||
skip = adapter->skip;
|
||||
for (g = adapter->buflist; g && size > 0; g = g_slist_next (g)) {
|
||||
GstBuffer *buf;
|
||||
|
||||
buf = g->data;
|
||||
if (offset < GST_BUFFER_SIZE (buf) - skip) {
|
||||
int n;
|
||||
|
||||
n = MIN (GST_BUFFER_SIZE (buf) - skip - offset, size);
|
||||
memcpy (dest, GST_BUFFER_DATA (buf) + skip + offset, n);
|
||||
|
||||
dest += n;
|
||||
offset = 0;
|
||||
size -= n;
|
||||
} else {
|
||||
offset -= GST_BUFFER_SIZE (buf) - skip;
|
||||
}
|
||||
skip = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_adapter_flush:
|
||||
* @adapter: a #GstAdapter
|
||||
|
|
|
@ -78,6 +78,8 @@ GstAdapter * gst_adapter_new (void);
|
|||
void gst_adapter_clear (GstAdapter *adapter);
|
||||
void gst_adapter_push (GstAdapter *adapter, GstBuffer* buf);
|
||||
const guint8 * gst_adapter_peek (GstAdapter *adapter, guint size);
|
||||
void gst_adapter_copy (GstAdapter *adapter, guint8 *dest,
|
||||
guint offset, guint size);
|
||||
void gst_adapter_flush (GstAdapter *adapter, guint flush);
|
||||
guint8* gst_adapter_take (GstAdapter *adapter, guint nbytes);
|
||||
GstBuffer* gst_adapter_take_buffer (GstAdapter *adapter, guint nbytes);
|
||||
|
|
Loading…
Reference in a new issue