summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2011-03-28 10:28:02 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2011-03-28 20:08:47 +0200
commita12373b2ee14ed943315db372ddbb21dc54d58cd (patch)
treea860c0499dbfbf8c97a6b4d27b8a8f6e155a9629
parent100a3799bbb0f522673bbb17175eba69d044544e (diff)
buffer: add more methods
-rw-r--r--gst/gstbuffer.c55
-rw-r--r--gst/gstbuffer.h4
-rw-r--r--gst/gstmemory.h6
3 files changed, 63 insertions, 2 deletions
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index 03aa45a1d..86ced8557 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -578,6 +578,20 @@ gst_buffer_get_size (GstBuffer * buffer)
}
/**
+ * 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.
* @size: a location for the size
@@ -682,6 +696,47 @@ gst_buffer_unmap (GstBuffer * buffer, gpointer data, gsize size)
}
/**
+ * 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.
* @offset: the offset to extract
diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h
index 71d80ace5..99d4be18d 100644
--- a/gst/gstbuffer.h
+++ b/gst/gstbuffer.h
@@ -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,
diff --git a/gst/gstmemory.h b/gst/gstmemory.h
index 8861ff972..99b2ee91a 100644
--- a/gst/gstmemory.h
+++ b/gst/gstmemory.h
@@ -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:
*