mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 21:51:09 +00:00
buffer: add more methods
This commit is contained in:
parent
100a3799bb
commit
a12373b2ee
3 changed files with 63 additions and 2 deletions
|
@ -577,6 +577,20 @@ gst_buffer_get_size (GstBuffer * buffer)
|
|||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_set_size:
|
||||
* @buffer: a #GstBuffer.
|
||||
* @size: the new size
|
||||
*
|
||||
* Set the total size of the buffer
|
||||
*/
|
||||
void
|
||||
gst_buffer_set_size (GstBuffer * buffer, gsize size)
|
||||
{
|
||||
/* FIXME */
|
||||
g_warning ("gst_buffer_set_size not imlpemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_map:
|
||||
* @buffer: a #GstBuffer.
|
||||
|
@ -681,6 +695,47 @@ gst_buffer_unmap (GstBuffer * buffer, gpointer data, gsize size)
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_fill:
|
||||
* @buffer: a #GstBuffer.
|
||||
* @offset: the offset to fill
|
||||
* @src: the source address
|
||||
* @size: the size to fill
|
||||
*
|
||||
* Copy @size bytes fro @src to @buffer at @offset.
|
||||
*/
|
||||
void
|
||||
gst_buffer_fill (GstBuffer * buffer, gsize offset, gpointer src, gsize size)
|
||||
{
|
||||
GPtrArray *arr = (GPtrArray *) buffer->memory;
|
||||
gsize i, len;
|
||||
guint8 *ptr = src;
|
||||
|
||||
len = arr->len;
|
||||
|
||||
for (i = 0; i < len && size > 0; i++) {
|
||||
guint8 *data;
|
||||
gsize ssize, tocopy;
|
||||
GstMemory *mem;
|
||||
|
||||
mem = g_ptr_array_index (arr, i);
|
||||
|
||||
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_WRITE);
|
||||
if (ssize > offset) {
|
||||
/* we have enough */
|
||||
tocopy = MIN (ssize - offset, size);
|
||||
memcpy (data + offset, ptr, tocopy);
|
||||
size -= tocopy;
|
||||
ptr += tocopy;
|
||||
offset = 0;
|
||||
} else {
|
||||
/* offset past buffer, skip */
|
||||
offset -= ssize;
|
||||
}
|
||||
gst_memory_unmap (mem, data, ssize);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_extract:
|
||||
* @buffer: a #GstBuffer.
|
||||
|
|
|
@ -300,10 +300,14 @@ void gst_buffer_take_memory (GstBuffer *buffer, GstMemory *mem);
|
|||
GstMemory * gst_buffer_peek_memory (GstBuffer *buffer, guint idx);
|
||||
void gst_buffer_remove_memory (GstBuffer *buffer, guint idx);
|
||||
|
||||
void gst_buffer_fill (GstBuffer *buffer, gsize offset,
|
||||
gpointer src, gsize size);
|
||||
void gst_buffer_extract (GstBuffer *buffer, gsize offset,
|
||||
gpointer dest, gsize size);
|
||||
|
||||
gsize gst_buffer_get_size (GstBuffer *buffer);
|
||||
void gst_buffer_set_size (GstBuffer *buffer, gsize size);
|
||||
void gst_buffer_trim (GstBuffer *buffer, gsize offset, gsize size);
|
||||
|
||||
/* getting memory */
|
||||
gpointer gst_buffer_map (GstBuffer *buffer, gsize *size, gsize *maxsize,
|
||||
|
|
|
@ -60,10 +60,12 @@ struct _GstMemory {
|
|||
};
|
||||
|
||||
typedef enum {
|
||||
GST_MAP_READ,
|
||||
GST_MAP_WRITE,
|
||||
GST_MAP_READ = (1 << 0),
|
||||
GST_MAP_WRITE = (1 << 1),
|
||||
} GstMapFlags;
|
||||
|
||||
#define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE)
|
||||
|
||||
/**
|
||||
* GST_MEMORY_TRACE_NAME:
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue