summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2002-03-17 14:31:20 +0000
committerBenjamin Otte <otte@gnome.org>2002-03-17 14:31:20 +0000
commit984ae14d7b057b790908b58ae97291f89c0d9c0d (patch)
tree11c83f8cab62e925120c534ffda1775c6e78002e
parentecc9fb54daa3e057723d10a72c30fb493b75ff2d (diff)
downloadgstreamer-984ae14d7b057b790908b58ae97291f89c0d9c0d.tar.gz
changes to the buffers /bufferpools:
Original commit message from CVS: changes to the buffers /bufferpools: - merge gstbufferpool.[ch] into gstbuffer.[ch] - fix gst_buffer_copy to work with the right pools - sub buffers are now ordinary buffers with their own pool, so we don't need the parent field anymore - updated filesrc to use the bufferpool changes if anyone is keen to try: gst-launch filesrc ! { queue ! mad ! { queue ! osssink } works here - you just should only compile mad and oss stuff from the plugins, the rest will probably not compile.
-rw-r--r--gst/Makefile.am2
-rw-r--r--gst/elements/gstfilesrc.c13
-rw-r--r--gst/gst.c1
-rw-r--r--gst/gstbuffer.c356
-rw-r--r--gst/gstbuffer.h55
-rw-r--r--gst/gstbufferpool.c221
-rw-r--r--gst/gstbufferpool.h80
-rw-r--r--gst/gstqueue.c15
-rw-r--r--plugins/elements/gstfilesrc.c13
-rw-r--r--plugins/elements/gstqueue.c15
-rw-r--r--tests/memchunk/gmemchunktest.c11
11 files changed, 354 insertions, 428 deletions
diff --git a/gst/Makefile.am b/gst/Makefile.am
index 993ae5be38..5ee155ec35 100644
--- a/gst/Makefile.am
+++ b/gst/Makefile.am
@@ -56,7 +56,6 @@ libgstreamer_la_SOURCES = \
$(GST_AUTOPLUG_SRC) \
gstbin.c \
gstbuffer.c \
- gstbufferpool.c \
gstcaps.c \
gstclock.c \
gstcpu.c \
@@ -116,7 +115,6 @@ libgstreamerinclude_HEADERS = \
gstautoplug.h \
gstbin.h \
gstbuffer.h \
- gstbufferpool.h \
gstcaps.h \
gstclock.h \
gstcpu.h \
diff --git a/gst/elements/gstfilesrc.c b/gst/elements/gstfilesrc.c
index b2fbe81b32..c669839a41 100644
--- a/gst/elements/gstfilesrc.c
+++ b/gst/elements/gstfilesrc.c
@@ -113,7 +113,12 @@ static gpointer gst_filesrc_srcpad_event (GstPad *pad, GstData *event);
/* state change */
static GstElementStateReturn gst_filesrc_change_state (GstElement *element);
/* bufferpool */
-static GstBuffer * gst_filesrc_buffer_new (GstBufferPool *pool, guint size);
+static GstBuffer * gst_filesrc_buffer_new (GstBufferPool *pool,
+ guint size);
+static GstBuffer * gst_filesrc_buffer_copy (GstBufferPool *pool,
+ const GstBuffer *buffer,
+ guint offset,
+ guint size);
static void gst_filesrc_buffer_dispose (GstData *buffer);
@@ -206,6 +211,7 @@ gst_filesrc_init (GstFileSrc *src)
src->pool = gst_buffer_pool_new ();
gst_buffer_pool_set_buffer_new_function (src->pool, gst_filesrc_buffer_new);
+ gst_buffer_pool_set_buffer_copy_function (src->pool, gst_filesrc_buffer_copy);
gst_buffer_pool_set_buffer_dispose_function (src->pool, gst_filesrc_buffer_dispose);
gst_buffer_pool_set_user_data (src->pool, src);
@@ -732,6 +738,11 @@ gst_filesrc_buffer_new (GstBufferPool *pool, guint size)
return buffer;
}
+static GstBuffer *
+gst_filesrc_buffer_copy (GstBufferPool *pool, const GstBuffer *buffer, guint offset, guint size)
+{
+ return gst_buffer_copy_part_from_pool (NULL, buffer, offset, size);
+}
static void
gst_filesrc_buffer_dispose (GstData *buffer)
{
diff --git a/gst/gst.c b/gst/gst.c
index 1dd3fe0a84..a50fea6f00 100644
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -298,7 +298,6 @@ init_post (void)
_gst_plugin_initialize ();
_gst_event_initialize ();
_gst_buffer_initialize ();
- _gst_buffer_pool_initialize ();
/* if we need to preload plugins */
if (preload_plugins) {
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index 9a50e5a08e..176e12771b 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -28,6 +28,24 @@
#include "gstobject.h"
static GMemChunk *_buffer_chunk = NULL;
+static GstBufferPool *_default_pool = NULL;
+static GstBufferPool *_sub_buffer_pool = NULL;
+
+static GstBuffer * gst_buffer_pool_default_buffer_new (GstBufferPool *pool,
+ guint size);
+static GstBuffer * gst_buffer_pool_default_buffer_copy (GstBufferPool *from_pool,
+ const GstBuffer *buffer,
+ guint offset,
+ guint size);
+static void gst_buffer_pool_default_buffer_dispose (GstData *buffer);
+
+static GstBuffer * gst_buffer_pool_sub_buffer_new (GstBufferPool *pool,
+ guint size);
+static GstBuffer * gst_buffer_pool_sub_buffer_copy (GstBufferPool *from_pool,
+ const GstBuffer *buffer,
+ guint offset,
+ guint size);
+static void gst_buffer_pool_sub_buffer_dispose (GstData *buffer);
void
_gst_buffer_initialize (void)
@@ -35,7 +53,15 @@ _gst_buffer_initialize (void)
gint buffersize = sizeof (GstBuffer);
if (_buffer_chunk == NULL)
{
+ /* create the default buffer chunk */
_buffer_chunk = g_mem_chunk_new ("GstBufferChunk", buffersize, buffersize * 128, G_ALLOC_AND_FREE);
+ /* create the default pool that uses g_malloc/free */
+ _default_pool = gst_buffer_pool_new ();
+ /* create the pool for subbuffers */
+ _sub_buffer_pool = gst_buffer_pool_new ();
+ gst_buffer_pool_set_buffer_new_function (_sub_buffer_pool, gst_buffer_pool_sub_buffer_new);
+ gst_buffer_pool_set_buffer_copy_function (_sub_buffer_pool, gst_buffer_pool_sub_buffer_copy);
+ gst_buffer_pool_set_buffer_dispose_function (_sub_buffer_pool, gst_buffer_pool_sub_buffer_dispose);
GST_INFO (GST_CAT_BUFFER, "Buffers are initialized now");
}
}
@@ -87,7 +113,6 @@ gst_buffer_init (GstBuffer *buffer, GstBufferPool *pool)
buffer->data = NULL;
buffer->size = 0;
- buffer->parent = NULL;
buffer->pool = pool;
buffer->pool_private = NULL;
}
@@ -102,9 +127,6 @@ gst_buffer_init (GstBuffer *buffer, GstBufferPool *pool)
void
gst_buffer_dispose (GstData *buffer)
{
- /* unreference the parent if there is one */
- gst_buffer_unparent (GST_BUFFER (buffer));
-
gst_data_unref (GST_DATA (GST_BUFFER (buffer)->pool));
gst_data_dispose (buffer);
}
@@ -123,72 +145,13 @@ gst_buffer_new (GstBufferPool *pool, guint size)
{
if (pool == NULL)
{
- GstBufferPool *def = gst_buffer_pool_default ();
+ GstBufferPool *def = _default_pool;
return def->buffer_new (def, size);
} else {
return pool->buffer_new (pool, size);
}
}
/**
- * gst_buffer_set_parent:
- * @buffer: buffer to set the parent for
- * @parent: parent to set
- *
- * Sets the buffers parent to the given one.
- */
-void
-gst_buffer_set_parent (GstBuffer *buffer, GstBuffer *parent, guint offset, guint size)
-{
- /* make sure we get valid data */
- g_return_if_fail (buffer != NULL);
- g_return_if_fail (parent != NULL);
- g_return_if_fail (buffer != parent);
- /* make sure we can get the data from the parent */
- g_return_if_fail (parent->size >= offset + size);
- /* do not reset the parent */
- if (buffer->parent == parent)
- return;
- /* if we have a parent, remove it */
- if (buffer->parent != NULL)
- gst_buffer_unparent (buffer);
- /* make sure buffer contains no data */
- g_return_if_fail (buffer->data == NULL);
- g_return_if_fail (buffer->size == 0);
-
- gst_data_ref (GST_DATA (parent));
- buffer->data = parent->data + offset;
- buffer->size = size;
- /* make sure we're child from a root buffer */
- while (parent->parent)
- {
- parent = parent->parent;
- }
- buffer->parent = parent;
- /* make sure nobody overwrites data in two buffers */
- GST_DATA_FLAG_SET(buffer, GST_DATA_READONLY);
- if (GST_DATA_IS_WRITABLE (parent))
- GST_DATA_FLAG_SET(parent, GST_DATA_READONLY);
-}
-/**
- * gst_buffer_unset_parent:
- * @buffer: buffer to unset the parent for
- *
- * Unsets the buffers parent and clears the data.
- * If the buffer has no parent, it simply returns.
- */
-void
-gst_buffer_unparent (GstBuffer *buffer)
-{
- g_return_if_fail (buffer != NULL);
- if (buffer->parent == NULL)
- return;
-
- gst_data_unref (GST_DATA (buffer->parent));
- buffer->parent = NULL;
- buffer->data = NULL;
- buffer->size = 0;
-}
-/**
* gst_buffer_create_sub:
* @parent: parent buffer
* @offset: offset into parent buffer
@@ -202,14 +165,32 @@ GstBuffer*
gst_buffer_create_sub (GstBuffer *parent, guint offset, guint size)
{
GstBuffer *buffer;
-
+ gpointer buffer_data;
+
g_return_val_if_fail (parent != NULL, NULL);
g_return_val_if_fail (GST_BUFFER_REFCOUNT(parent) > 0, NULL);
g_return_val_if_fail (size > 0, NULL);
-
- buffer = gst_buffer_new (parent->pool, 0);
-
- gst_buffer_set_parent (buffer, parent, offset, size);
+ g_return_val_if_fail (parent->size >= offset + size, NULL);
+ /* remember the data for the new buffer */
+ buffer_data = parent->data + offset;
+ /* make sure we're child not child from a child buffer */
+ while (parent->pool == _sub_buffer_pool)
+ {
+ parent = GST_BUFFER (parent->pool_private);
+ }
+ /* ref the real parent */
+ gst_data_ref (GST_DATA (parent));
+ /* make sure nobody overwrites data in the parent */
+ if (GST_DATA_IS_WRITABLE (parent))
+ GST_DATA_FLAG_SET(parent, GST_DATA_READONLY);
+ /* create the new buffer */
+ buffer = gst_buffer_new (_sub_buffer_pool, 0);
+ /* make sure nobody overwrites data in the new buffer */
+ GST_DATA_FLAG_SET(buffer, GST_DATA_READONLY);
+ /* set the right values in the child */
+ buffer->pool_private = parent;
+ buffer->data = buffer_data;
+ buffer->size = size;
return buffer;
}
@@ -226,8 +207,7 @@ gst_buffer_create_sub (GstBuffer *parent, guint offset, guint size)
* Returns: new buffer
*/
GstBuffer*
-gst_buffer_append (GstBuffer *buffer,
- GstBuffer *append)
+gst_buffer_append (GstBuffer *buffer, GstBuffer *append)
{
GstBuffer *newbuf;
@@ -245,19 +225,29 @@ gst_buffer_append (GstBuffer *buffer,
return newbuf;
}
/**
- * gst_buffer_copy:
+ * gst_buffer_copy_part_from_pool:
+ * @pool: the GstBufferPool to create the buffer from or NULL to use the default
* @buffer: the orignal GstBuffer to make a copy of
+ * @offset: the offset into the buffer
+ * @offset: the offset into the buffer
*
- * Make a full copy of the give buffer, data and all.
+ * Make a full copy of the given buffer with the given part of the data. Use the
+ * given bufferpool to create the buffer.
*
* Returns: new buffer
*/
GstBuffer *
-gst_buffer_copy (const GstBuffer *buffer)
+gst_buffer_copy_part_from_pool (GstBufferPool *pool, const GstBuffer *buffer, guint offset, guint size)
{
- g_return_val_if_fail (GST_BUFFER_REFCOUNT(buffer) > 0, NULL);
-
- return buffer->pool->buffer_copy (buffer);
+ GstBufferPool *use_pool;
+
+ g_return_val_if_fail (buffer != NULL, NULL);
+ g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
+ g_return_val_if_fail (GST_BUFFER_REFCOUNT (buffer) > 0, NULL);
+ g_return_val_if_fail (buffer->size >= offset + size, NULL);
+
+ use_pool = pool ? pool : _default_pool;
+ return use_pool->buffer_copy (use_pool, buffer, offset, size);
}
/**
* gst_buffer_is_span_fast:
@@ -274,8 +264,10 @@ gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2)
g_return_val_if_fail (GST_BUFFER_REFCOUNT(buf1) > 0, FALSE);
g_return_val_if_fail (GST_BUFFER_REFCOUNT(buf2) > 0, FALSE);
- return (buf1->parent && buf2->parent &&
- (buf1->parent == buf2->parent) &&
+ /* it's only fast if we have subbuffers of the same parent */
+ return ((buf1->pool == _sub_buffer_pool) &&
+ (buf2->pool == _sub_buffer_pool) &&
+ (buf1->pool_private == buf2->pool_private) &&
((buf1->data + buf1->size) == buf2->data));
}
/**
@@ -304,14 +296,16 @@ gst_buffer_span (GstBuffer *buf1, guint offset, GstBuffer *buf2, guint len)
g_return_val_if_fail (GST_BUFFER_REFCOUNT(buf1) > 0, NULL);
g_return_val_if_fail (GST_BUFFER_REFCOUNT(buf2) > 0, NULL);
+ g_return_val_if_fail (len > 0, NULL);
/* if the two buffers have the same parent and are adjacent */
if (gst_buffer_is_span_fast(buf1,buf2)) {
+ GstBuffer *parent = GST_BUFFER (buf1->pool_private);
/* we simply create a subbuffer of the common parent */
- newbuf = gst_buffer_create_sub (buf1->parent, buf1->data - buf1->parent->data + offset, len);
+ newbuf = gst_buffer_create_sub (parent, buf1->data - parent->data + offset, len);
}
else {
- /* g_print ("slow path taken in buffer_span\n"); */
+ GST_DEBUG (GST_CAT_BUFFER,"slow path taken while spanning buffers %p and %p", buffer, append);
/* otherwise we simply have to brute-force copy the buffers */
newbuf = gst_buffer_new (buf1->pool, len);
@@ -357,3 +351,203 @@ gst_buffer_merge (GstBuffer *buf1, GstBuffer *buf2)
return result;
}
+/**
+ * gst_buffer_pool_new:
+ *
+ * Create a new buffer pool.
+ *
+ * Returns: new buffer pool
+ */
+GstBufferPool*
+gst_buffer_pool_new (void)
+{
+ GstBufferPool *pool;
+
+ pool = g_new0 (GstBufferPool, 1);
+ GST_DEBUG (GST_CAT_BUFFER,"allocating new buffer pool %p\n", pool);
+
+ /* init data struct */
+ gst_data_init (GST_DATA (pool));
+ GST_DATA_TYPE (pool) = GST_DATA_BUFFERPOOL;
+
+ /* set functions */
+ pool->buffer_new = gst_buffer_pool_default_buffer_new;
+ pool->buffer_copy = gst_buffer_pool_default_buffer_copy;
+ pool->buffer_dispose = gst_buffer_pool_default_buffer_dispose;
+ pool->buffer_free = (GstDataFreeFunction) gst_buffer_free;
+
+ return pool;
+}
+/**
+ * gst_buffer_pool_set_buffer_new_function:
+ * @pool: the pool to set the buffer create function for
+ * @create: the create function
+ *
+ * Sets the function that will be called when a buffer is created
+ * from this pool.
+ */
+void
+gst_buffer_pool_set_buffer_new_function (GstBufferPool *pool,
+ GstBufferPoolBufferNewFunction create)
+{
+ g_return_if_fail (pool != NULL);
+ g_return_if_fail (create != NULL);
+
+ pool->buffer_new = create;
+}
+/**
+ * gst_buffer_pool_set_buffer_dispose_function:
+ * @pool: the pool to set the buffer dispose function for
+ * @free: the dispose function
+ *
+ * Sets the function that will be called when a buffer should be disposed.
+ */
+void
+gst_buffer_pool_set_buffer_dispose_function (GstBufferPool *pool,
+ GstDataFreeFunction dispose)
+{
+ g_return_if_fail (pool != NULL);
+ g_return_if_fail (dispose != NULL);
+
+ pool->buffer_dispose = dispose;
+}
+/**
+ * gst_buffer_pool_set_buffer_free_function:
+ * @pool: the pool to set the buffer free function for
+ * @free: the free function
+ *
+ * Sets the function that will be called when a buffer should be freed.
+ */
+void
+gst_buffer_pool_set_buffer_free_function (GstBufferPool *pool,
+ GstDataFreeFunction free)
+{
+ g_return_if_fail (pool != NULL);
+ g_return_if_fail (free != NULL);
+
+ pool->buffer_free = free;
+}
+/**
+ * gst_buffer_pool_set_buffer_copy_function:
+ * @pool: the pool to set the buffer copy function for
+ * @copy: the copy function
+ *
+ * Sets the function that will be called when a buffer is copied.
+ * Your function does not need to check the given parameters, they will
+ * be checked before calling your function.
+ */
+void
+gst_buffer_pool_set_buffer_copy_function (GstBufferPool *pool, GstBufferPoolBufferCopyFunction copy)
+{
+ g_return_if_fail (pool != NULL);
+ g_return_if_fail (copy != NULL);
+
+ pool->buffer_copy = copy;
+}
+/**
+ * gst_buffer_pool_set_user_data:
+ * @pool: the pool to set the user data for
+ * @user_data: any user data to be passed to the create/destroy buffer functions
+ * and the destroy hook
+ *
+ * You can put your private data here.
+ */
+void
+gst_buffer_pool_set_user_data (GstBufferPool *pool, gpointer user_data)
+{
+ g_return_if_fail (pool != NULL);
+
+ pool->user_data = user_data;
+}
+
+/**
+ * gst_buffer_pool_get_user_data:
+ * @pool: the pool to get the user data from
+ *
+ * gets user data
+ *
+ * Returns: The user data of this bufferpool
+ */
+gpointer
+gst_buffer_pool_get_user_data (GstBufferPool *pool)
+{
+ g_return_val_if_fail (pool != NULL, NULL);
+
+ return pool->user_data;
+}
+
+static GstBuffer*
+gst_buffer_pool_default_buffer_new (GstBufferPool *pool, guint size)
+{
+ GstBuffer *buffer;
+
+ g_return_val_if_fail((buffer = gst_buffer_alloc()), NULL);
+
+ GST_INFO (GST_CAT_BUFFER,"creating new buffer %p from pool %p", buffer, pool);
+
+ gst_buffer_init (buffer, pool);
+
+ GST_BUFFER_DATA(buffer) = size > 0 ? g_malloc (size) : NULL;
+ GST_BUFFER_SIZE(buffer) = GST_BUFFER_DATA(buffer) ? size : 0;
+
+ return buffer;
+}
+static GstBuffer *
+gst_buffer_pool_default_buffer_copy (GstBufferPool *from_pool, const GstBuffer *buffer, guint offset, guint size)
+{
+ GstBuffer *newbuf;
+
+ /* allocate a new buffer with the right size */
+ newbuf = gst_buffer_new (from_pool, size);
+ /* copy all relevant data stuff */
+ gst_data_copy (GST_DATA (newbuf), GST_DATA (buffer));
+ /* copy the data straight across */
+ memcpy (newbuf->data, buffer->data + offset, size);
+
+ return newbuf;
+}
+static void
+gst_buffer_pool_default_buffer_dispose(GstData *buffer)
+{
+ GstBuffer *buf = GST_BUFFER (buffer);
+
+ gst_buffer_dispose (buffer);
+ g_free (buf->data);
+ buf->data = NULL;
+ buf->size = 0;
+}
+static GstBuffer *
+gst_buffer_pool_sub_buffer_new (GstBufferPool *pool, guint size)
+{
+ GstBuffer *buffer;
+
+ g_return_val_if_fail((buffer = gst_buffer_alloc()), NULL);
+
+ GST_DEBUG (GST_CAT_BUFFER, "creating new subbuffer %p", buffer, pool);
+
+ gst_buffer_init (buffer, pool);
+
+ GST_BUFFER_DATA(buffer) = NULL;
+ GST_BUFFER_SIZE(buffer) = 0;
+
+ return buffer;
+}
+static GstBuffer *
+gst_buffer_pool_sub_buffer_copy (GstBufferPool *from_pool, const GstBuffer *buffer, guint offset, guint size)
+{
+ GstBuffer *parent = GST_BUFFER (buffer->pool_private);
+ guint new_offset = buffer->data - parent->data;
+ GstBufferPool *use_pool = from_pool == _sub_buffer_pool ? NULL : from_pool;
+ return parent->pool->buffer_copy (use_pool, parent, new_offset, size);
+}
+static void
+gst_buffer_pool_sub_buffer_dispose (GstData *buffer)
+{
+ GstBuffer *buf = GST_BUFFER (buffer);
+
+ buf->data = NULL;
+ buf->size = 0;
+ gst_data_unref (GST_DATA (buf->pool_private));
+ buf->pool_private = NULL;
+ gst_buffer_dispose (buffer);
+}
diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h
index fe01ed671e..7c0316b746 100644
--- a/gst/gstbuffer.h
+++ b/gst/gstbuffer.h
@@ -49,6 +49,9 @@
extern "C" {
#endif /* __cplusplus */
+typedef struct _GstBuffer GstBuffer;
+typedef struct _GstBufferPool GstBufferPool;
+
/*
#define GST_BUFFER(buf) (((GstData*)(buf))->type == GST_BUFFER ? (GstBuffer *)(buf) : NULL)
*/
@@ -78,31 +81,43 @@ extern "C" {
#define GST_BUFFER_TRYLOCK(buf) (g_mutex_trylock(GST_BUFFER(buf)->lock))
#define GST_BUFFER_UNLOCK(buf) (g_mutex_unlock(GST_BUFFER(buf)->lock))
-
enum {
GST_BUFFER_ORIGINAL = GST_DATA_FLAG_LAST,
GST_BUFFER_FLAG_LAST,
};
-typedef struct _GstBuffer GstBuffer;
+/* bufferpools */
+#define GST_BUFFER_POOL(pool) ((GstBufferPool *)(pool))
+
+typedef GstBuffer * (*GstBufferPoolBufferNewFunction) (GstBufferPool *pool, guint size);
+typedef GstBuffer * (*GstBufferPoolBufferCopyFunction) (GstBufferPool *pool, const GstBuffer *buffer, guint offset, guint size);
-#include <gst/gstbufferpool.h>
struct _GstBuffer {
GstData data_type;
/* pointer to data and its size */
gpointer data;
- guint32 size;
-
- /* subbuffer support, who's my parent? */
- GstBuffer *parent;
+ guint size;
/* this is a pointer to the buffer pool (if any) */
GstBufferPool * pool;
gpointer pool_private;
};
+struct _GstBufferPool {
+ /* easiest way to get refcounting */
+ GstData data;
+
+ GstBufferPoolBufferNewFunction buffer_new;
+ GstBufferPoolBufferCopyFunction buffer_copy;
+ GstDataFreeFunction buffer_dispose;
+ GstDataFreeFunction buffer_free;
+
+ gpointer user_data;
+};
+
+
/* initialization */
void _gst_buffer_initialize (void);
@@ -118,14 +133,11 @@ void gst_buffer_dispose (GstData *data);
GstBuffer* gst_buffer_new (GstBufferPool *pool, guint size);
/* creating a subbuffer */
-GstBuffer* gst_buffer_create_sub (GstBuffer *parent, guint32 offset, guint32 size);
+GstBuffer* gst_buffer_create_sub (GstBuffer *parent, guint offset, guint size);
/* copy buffer */
-GstBuffer* gst_buffer_copy (const GstBuffer *buffer);
-
-/* parentage */
-void gst_buffer_set_parent (GstBuffer *buffer, GstBuffer *parent, guint offset, guint size);
-void gst_buffer_unparent (GstBuffer *buffer);
+#define gst_buffer_copy(buffer) gst_buffer_copy_part_from_pool (buffer->pool, buffer, 0, buffer->size);
+GstBuffer* gst_buffer_copy_part_from_pool (GstBufferPool *pool, const GstBuffer *buffer, guint offset, guint size);
/* merge, span, or append two buffers, intelligently */
GstBuffer* gst_buffer_merge (GstBuffer *buf1, GstBuffer *buf2);
@@ -134,6 +146,23 @@ GstBuffer* gst_buffer_append (GstBuffer *buffer, GstBuffer *append);
gboolean gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2);
+/* creating a new buffer pool from scratch */
+GstBufferPool * gst_buffer_pool_new (void);
+
+/* setting create and destroy functions */
+void gst_buffer_pool_set_buffer_new_function (GstBufferPool *pool,
+ GstBufferPoolBufferNewFunction create);
+void gst_buffer_pool_set_buffer_copy_function (GstBufferPool *pool,
+ GstBufferPoolBufferCopyFunction copy);
+void gst_buffer_pool_set_buffer_dispose_function (GstBufferPool *pool,
+ GstDataFreeFunction dispose);
+void gst_buffer_pool_set_buffer_free_function (GstBufferPool *pool,
+ GstDataFreeFunction free);
+void gst_buffer_pool_set_user_data (GstBufferPool *pool,
+ gpointer user_data);
+gpointer gst_buffer_pool_get_user_data (GstBufferPool *pool);
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/gst/gstbufferpool.c b/gst/gstbufferpool.c
deleted file mode 100644
index 72ccb0aa98..0000000000
--- a/gst/gstbufferpool.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/* GStreamer
- * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
- * 2000 Wim Taymans <wtay@chello.be>
- *
- * gstbufferpool.c: Buffer-pool operations
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-
-#include "gst_private.h"
-
-#include "gstbuffer.h"
-/* debugging and error checking */
-#include "gstlog.h"
-#include "gstinfo.h"
-
-static GstBufferPool *_default_pool = NULL;
-
-static GstBuffer * gst_buffer_pool_default_buffer_new (GstBufferPool *pool,
- guint size);
-static GstBuffer * gst_buffer_pool_default_buffer_copy (const GstBuffer *buffer);
-static void gst_buffer_pool_default_buffer_dispose (GstData *buffer);
-
-void
-_gst_buffer_pool_initialize (void)
-{
- if (_default_pool == NULL)
- {
- _default_pool = gst_buffer_pool_new ();
- GST_INFO (GST_CAT_BUFFER, "Buffer pools are initialized now");
- }
-}
-/**
- * gst_buffer_pool_default:
- *
- * Get the default buffer pool.
- *
- * Returns: the default buffer pool
- */
-GstBufferPool *
-gst_buffer_pool_default (void)
-{
- return _default_pool;
-}
-/**
- * gst_buffer_pool_new:
- *
- * Create a new buffer pool.
- *
- * Returns: new buffer pool
- */
-GstBufferPool*
-gst_buffer_pool_new (void)
-{
- GstBufferPool *pool;
-
- pool = g_new0 (GstBufferPool, 1);
- GST_DEBUG (GST_CAT_BUFFER,"allocating new buffer pool %p\n", pool);
-
- /* init data struct */
- gst_data_init (GST_DATA (pool));
- GST_DATA_TYPE (pool) = GST_DATA_BUFFERPOOL;
-
- /* set functions */
- pool->buffer_new = gst_buffer_pool_default_buffer_new;
- pool->buffer_copy = gst_buffer_pool_default_buffer_copy;
- pool->buffer_dispose = gst_buffer_pool_default_buffer_dispose;
- pool->buffer_free = (GstDataFreeFunction) gst_buffer_free;
-
- return pool;
-}
-/**
- * gst_buffer_pool_set_buffer_new_function:
- * @pool: the pool to set the buffer create function for
- * @create: the create function
- *
- * Sets the function that will be called when a buffer is created
- * from this pool.
- */
-void
-gst_buffer_pool_set_buffer_new_function (GstBufferPool *pool,
- GstBufferPoolBufferNewFunction create)
-{
- g_return_if_fail (pool != NULL);
- g_return_if_fail (create != NULL);
-
- pool->buffer_new = create;
-}
-/**
- * gst_buffer_pool_set_buffer_dispose_function:
- * @pool: the pool to set the buffer dispose function for
- * @free: the dispose function
- *
- * Sets the function that will be called when a buffer should be disposed.
- */
-void
-gst_buffer_pool_set_buffer_dispose_function (GstBufferPool *pool,
- GstDataFreeFunction dispose)
-{
- g_return_if_fail (pool != NULL);
- g_return_if_fail (dispose != NULL);
-
- pool->buffer_dispose = dispose;
-}
-/**
- * gst_buffer_pool_set_buffer_free_function:
- * @pool: the pool to set the buffer free function for
- * @free: the free function
- *
- * Sets the function that will be called when a buffer should be freed.
- */
-void
-gst_buffer_pool_set_buffer_free_function (GstBufferPool *pool,
- GstDataFreeFunction free)
-{
- g_return_if_fail (pool != NULL);
- g_return_if_fail (free != NULL);
-
- pool->buffer_free = free;
-}
-/**
- * gst_buffer_pool_set_buffer_copy_function:
- * @pool: the pool to set the buffer copy function for
- * @copy: the copy function
- *
- * Sets the function that will be called when a buffer is copied.
- */
-void
-gst_buffer_pool_set_buffer_copy_function (GstBufferPool *pool, GstBufferPoolBufferCopyFunction copy)
-{
- g_return_if_fail (pool != NULL);
- g_return_if_fail (copy != NULL);
-
- pool->buffer_copy = copy;
-}
-/**
- * gst_buffer_pool_set_user_data:
- * @pool: the pool to set the user data for
- * @user_data: any user data to be passed to the create/destroy buffer functions
- * and the destroy hook
- *
- * You can put your private data here.
- */
-void
-gst_buffer_pool_set_user_data (GstBufferPool *pool, gpointer user_data)
-{
- g_return_if_fail (pool != NULL);
-
- pool->user_data = user_data;
-}
-
-/**
- * gst_buffer_pool_get_user_data:
- * @pool: the pool to get the user data from
- *
- * gets user data
- *
- * Returns: The user data of this bufferpool
- */
-gpointer
-gst_buffer_pool_get_user_data (GstBufferPool *pool)
-{
- g_return_val_if_fail (pool != NULL, NULL);
-
- return pool->user_data;
-}
-
-static GstBuffer*
-gst_buffer_pool_default_buffer_new (GstBufferPool *pool, guint size)
-{
- GstBuffer *buffer;
-
- g_return_val_if_fail((buffer = gst_buffer_alloc()), NULL);
-
- GST_INFO (GST_CAT_BUFFER,"creating new buffer %p from pool %p", buffer, pool);
-
- gst_buffer_init (buffer, pool);
-
- GST_BUFFER_DATA(buffer) = size > 0 ? g_malloc (size) : NULL;
- GST_BUFFER_SIZE(buffer) = GST_BUFFER_DATA(buffer) ? size : 0;
-
- return buffer;
-}
-GstBuffer *
-gst_buffer_pool_default_buffer_copy (const GstBuffer *buffer)
-{
- GstBuffer *newbuf;
-
- /* allocate a new buffer with the right size */
- newbuf = gst_buffer_new (buffer->pool, buffer->size);
- /* copy all relevant data stuff */
- gst_data_copy (GST_DATA (newbuf), GST_DATA (buffer));
- /* copy the data straight across */
- memcpy (newbuf->data, buffer->data, buffer->size);
-
- return newbuf;
-}
-static void
-gst_buffer_pool_default_buffer_dispose(GstData *buffer)
-{
- GstBuffer *buf = GST_BUFFER (buffer);
-
- gst_buffer_dispose (buffer);
- g_free (buf->data);
- buf->data = NULL;
- buf->size = 0;
-}
diff --git a/gst/gstbufferpool.h b/gst/gstbufferpool.h
deleted file mode 100644
index 85e7479a1f..0000000000
--- a/gst/gstbufferpool.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* GStreamer
- * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
- * 2000 Wim Taymans <wtay@chello.be>
- *
- * gstbufferpool.h: Header for buffer-pool management
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GST_BUFFER_POOL_H__
-#define __GST_BUFFER_POOL_H__
-
-#include <gst/gstbuffer.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-
-#define GST_BUFFER_POOL(pool) ((GstBufferPool *)(pool))
-
-typedef struct _GstBufferPool GstBufferPool;
-
-typedef GstBuffer * (*GstBufferPoolBufferNewFunction) (GstBufferPool *pool, guint size);
-typedef GstBuffer * (*GstBufferPoolBufferCopyFunction) (const GstBuffer *buffer);
-
-struct _GstBufferPool {
- /* easiest way to get refcounting */
- GstData data;
-
- GstBufferPoolBufferNewFunction buffer_new;
- GstBufferPoolBufferCopyFunction buffer_copy;
- GstDataFreeFunction buffer_dispose;
- GstDataFreeFunction buffer_free;
-
- gpointer user_data;
-};
-
-void _gst_buffer_pool_initialize (void);
-
-/* creating a new buffer pool from scratch */
-GstBufferPool * gst_buffer_pool_new (void);
-
-/* getting the default bufferpool */
-GstBufferPool * gst_buffer_pool_default (void);
-
-
-/* setting create and destroy functions */
-void gst_buffer_pool_set_buffer_new_function (GstBufferPool *pool,
- GstBufferPoolBufferNewFunction create);
-void gst_buffer_pool_set_buffer_copy_function (GstBufferPool *pool,
- GstBufferPoolBufferCopyFunction copy);
-void gst_buffer_pool_set_buffer_dispose_function (GstBufferPool *pool,
- GstDataFreeFunction dispose);
-void gst_buffer_pool_set_buffer_free_function (GstBufferPool *pool,
- GstDataFreeFunction free);
-void gst_buffer_pool_set_user_data (GstBufferPool *pool,
- gpointer user_data);
-gpointer gst_buffer_pool_get_user_data (GstBufferPool *pool);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-
-#endif /* __GST_BUFFER_POOL_H__ */
diff --git a/gst/gstqueue.c b/gst/gstqueue.c
index 08bd4810ca..dfbce85c03 100644
--- a/gst/gstqueue.c
+++ b/gst/gstqueue.c
@@ -328,7 +328,7 @@ restart:
if (queue->upstream_event)
{
GstPad *peer = GST_PAD_PEER (pad);
- g_print ("handling event\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "handling event %p\n", queue->upstream_event);
g_mutex_lock (queue->upstream_mutex);
if (peer)
@@ -340,7 +340,7 @@ restart:
queue->upstream_event = NULL;
g_cond_signal (queue->upstream_cond);
g_mutex_unlock (queue->upstream_mutex);
- g_print ("done handling event\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "done handling event %p\n", queue->upstream_event);
}
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "adding buffer %p of size %d\n", buf, GST_BUFFER_SIZE(buf));
@@ -429,12 +429,10 @@ restart:
/* FIXME: we're poking in AsyncQueue internals here */
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d\n", g_async_queue_length (queue->queue), queue->size);
- g_print ("waiting for not null\n");
g_mutex_lock (queue->upstream_mutex);
if (queue->upstream_event == NULL)
g_cond_wait (queue->not_full, queue->upstream_mutex);
g_mutex_unlock (queue->upstream_mutex);
- g_print ("not null\n");
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_full signal\n");
goto restart;
}
@@ -522,14 +520,13 @@ restart:
}
}
- GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", g_async_queue_length_unlocked (queue->queue), queue->size);
g_get_current_time (&timeval);
g_time_val_add (&timeval, queue->max_wait);
- g_print ("waiting for data\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", g_async_queue_length_unlocked (queue->queue), queue->size);
data = g_async_queue_timed_pop_unlocked (queue->queue, &timeval);
- g_print ("%s\n", data == NULL ? "timer goes off while waiting for data\n" : "data available\n");
if (data == NULL)
{
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "woken up by timer\n");
g_async_queue_unlock (queue->queue);
gst_element_yield (GST_ELEMENT (data));
goto restart;
@@ -679,10 +676,10 @@ gst_queue_upstream_event (GstPad *pad, GstData *event)
gst_data_ref (event);
queue->upstream_event = event;
g_cond_signal (queue->not_full);
- g_print ("waiting for handling of upstream event\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for handling of upstream event %p\n", queue->upstream_event);
while (queue->upstream_event != NULL)
g_cond_wait (queue->upstream_cond, queue->upstream_mutex);
- g_print ("upstream event handled\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "upstream event handled\n");
ret = queue->upstream_return;
queue->upstream_return = NULL;
g_mutex_unlock (queue->upstream_mutex);
diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c
index b2fbe81b32..c669839a41 100644
--- a/plugins/elements/gstfilesrc.c
+++ b/plugins/elements/gstfilesrc.c
@@ -113,7 +113,12 @@ static gpointer gst_filesrc_srcpad_event (GstPad *pad, GstData *event);
/* state change */
static GstElementStateReturn gst_filesrc_change_state (GstElement *element);
/* bufferpool */
-static GstBuffer * gst_filesrc_buffer_new (GstBufferPool *pool, guint size);
+static GstBuffer * gst_filesrc_buffer_new (GstBufferPool *pool,
+ guint size);
+static GstBuffer * gst_filesrc_buffer_copy (GstBufferPool *pool,
+ const GstBuffer *buffer,
+ guint offset,
+ guint size);
static void gst_filesrc_buffer_dispose (GstData *buffer);
@@ -206,6 +211,7 @@ gst_filesrc_init (GstFileSrc *src)
src->pool = gst_buffer_pool_new ();
gst_buffer_pool_set_buffer_new_function (src->pool, gst_filesrc_buffer_new);
+ gst_buffer_pool_set_buffer_copy_function (src->pool, gst_filesrc_buffer_copy);
gst_buffer_pool_set_buffer_dispose_function (src->pool, gst_filesrc_buffer_dispose);
gst_buffer_pool_set_user_data (src->pool, src);
@@ -732,6 +738,11 @@ gst_filesrc_buffer_new (GstBufferPool *pool, guint size)
return buffer;
}
+static GstBuffer *
+gst_filesrc_buffer_copy (GstBufferPool *pool, const GstBuffer *buffer, guint offset, guint size)
+{
+ return gst_buffer_copy_part_from_pool (NULL, buffer, offset, size);
+}
static void
gst_filesrc_buffer_dispose (GstData *buffer)
{
diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c
index 08bd4810ca..dfbce85c03 100644
--- a/plugins/elements/gstqueue.c
+++ b/plugins/elements/gstqueue.c
@@ -328,7 +328,7 @@ restart:
if (queue->upstream_event)
{
GstPad *peer = GST_PAD_PEER (pad);
- g_print ("handling event\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "handling event %p\n", queue->upstream_event);
g_mutex_lock (queue->upstream_mutex);
if (peer)
@@ -340,7 +340,7 @@ restart:
queue->upstream_event = NULL;
g_cond_signal (queue->upstream_cond);
g_mutex_unlock (queue->upstream_mutex);
- g_print ("done handling event\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "done handling event %p\n", queue->upstream_event);
}
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "adding buffer %p of size %d\n", buf, GST_BUFFER_SIZE(buf));
@@ -429,12 +429,10 @@ restart:
/* FIXME: we're poking in AsyncQueue internals here */
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d\n", g_async_queue_length (queue->queue), queue->size);
- g_print ("waiting for not null\n");
g_mutex_lock (queue->upstream_mutex);
if (queue->upstream_event == NULL)
g_cond_wait (queue->not_full, queue->upstream_mutex);
g_mutex_unlock (queue->upstream_mutex);
- g_print ("not null\n");
GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_full signal\n");
goto restart;
}
@@ -522,14 +520,13 @@ restart:
}
}
- GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", g_async_queue_length_unlocked (queue->queue), queue->size);
g_get_current_time (&timeval);
g_time_val_add (&timeval, queue->max_wait);
- g_print ("waiting for data\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", g_async_queue_length_unlocked (queue->queue), queue->size);
data = g_async_queue_timed_pop_unlocked (queue->queue, &timeval);
- g_print ("%s\n", data == NULL ? "timer goes off while waiting for data\n" : "data available\n");
if (data == NULL)
{
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "woken up by timer\n");
g_async_queue_unlock (queue->queue);
gst_element_yield (GST_ELEMENT (data));
goto restart;
@@ -679,10 +676,10 @@ gst_queue_upstream_event (GstPad *pad, GstData *event)
gst_data_ref (event);
queue->upstream_event = event;
g_cond_signal (queue->not_full);
- g_print ("waiting for handling of upstream event\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for handling of upstream event %p\n", queue->upstream_event);
while (queue->upstream_event != NULL)
g_cond_wait (queue->upstream_cond, queue->upstream_mutex);
- g_print ("upstream event handled\n");
+ GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "upstream event handled\n");
ret = queue->upstream_return;
queue->upstream_return = NULL;
g_mutex_unlock (queue->upstream_mutex);
diff --git a/tests/memchunk/gmemchunktest.c b/tests/memchunk/gmemchunktest.c
index b3301f13dd..1a56c26978 100644
--- a/tests/memchunk/gmemchunktest.c
+++ b/tests/memchunk/gmemchunktest.c
@@ -3,7 +3,6 @@
#define MAX_THREADS 100
static GMemChunk *_chunks;
-static GMutex *_lock;
static gint num_allocs;
static gint num_threads;
@@ -11,20 +10,13 @@ static gint num_threads;
static gpointer
alloc_chunk (void)
{
- gpointer ret;
- g_mutex_lock (_lock);
- ret = g_mem_chunk_alloc (_chunks);
- g_mutex_unlock (_lock);
-
- return ret;
+ return g_mem_chunk_alloc (_chunks);
}
static void
free_chunk (gpointer chunk)
{
- g_mutex_lock (_lock);
g_mem_chunk_free (_chunks, chunk);
- g_mutex_unlock (_lock);
}
@@ -61,7 +53,6 @@ main (gint argc, gchar *argv[])
num_allocs = atoi (argv[2]);
_chunks = g_mem_chunk_new ("test", 32, 32 * 16, G_ALLOC_AND_FREE);
- _lock = g_mutex_new ();
for(t=0; t < num_threads; t++) {
rc = pthread_create (&threads[t], NULL, run_test, (void *)t);