summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2011-02-22 12:35:45 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2011-03-02 11:33:24 +0100
commita55bc30f81d8355e61a2fef4f6b2df5099f1797f (patch)
tree2ebfd187d1c9ea726411c61949f14e387cd1437d /gst
parent0a89debaf72bfa9f1a5b4e3bed8dc0f793f8b574 (diff)
buffer: add pool to buffer structure
Keep a pointer to the bufferpool. Release the buffer to the pool when finalizing. Make sure the pool sets itself as the pool member of buffers that it sends out.
Diffstat (limited to 'gst')
-rw-r--r--gst/gstbuffer.c2
-rw-r--r--gst/gstbuffer.h6
-rw-r--r--gst/gstbufferpool.c16
-rw-r--r--gst/gstbufferpool.h1
4 files changed, 21 insertions, 4 deletions
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index b8774a8e6..6cb270fdc 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -123,6 +123,7 @@
#endif
#include "gstbuffer.h"
+#include "gstbufferpool.h"
#include "gstinfo.h"
#include "gstutils.h"
#include "gstminiobject.h"
@@ -290,6 +291,7 @@ static void
_gst_buffer_free (GstBuffer * buffer)
{
GstMetaItem *walk, *next;
+ GstBufferPool *pool;
g_return_if_fail (buffer != NULL);
diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h
index 02e8a8f25..0fad0b367 100644
--- a/gst/gstbuffer.h
+++ b/gst/gstbuffer.h
@@ -30,10 +30,11 @@
G_BEGIN_DECLS
-typedef struct _GstBuffer GstBuffer;
-
extern GType _gst_buffer_type;
+typedef struct _GstBuffer GstBuffer;
+typedef struct _GstBufferPool GstBufferPool;
+
/**
* GST_BUFFER_TRACE_NAME:
*
@@ -284,6 +285,7 @@ struct _GstBuffer {
/* ABI Added */
GFreeFunc free_func;
GstBuffer *parent;
+ GstBufferPool *pool;
gpointer priv;
};
diff --git a/gst/gstbufferpool.c b/gst/gstbufferpool.c
index 8ac4cb6ca..d4837129f 100644
--- a/gst/gstbufferpool.c
+++ b/gst/gstbufferpool.c
@@ -633,8 +633,13 @@ gst_buffer_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
else
result = GST_FLOW_NOT_SUPPORTED;
- if (G_UNLIKELY (result != GST_FLOW_OK))
+ if (G_LIKELY (result == GST_FLOW_OK)) {
+ /* all buffers from the pool point to the pool and have the refcount of the
+ * pool incremented */
+ (*buffer)->pool = gst_object_ref (pool);
+ } else {
dec_outstanding (pool);
+ }
return result;
}
@@ -666,10 +671,19 @@ gst_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
g_return_if_fail (GST_IS_BUFFER_POOL (pool));
g_return_if_fail (buffer != NULL);
+ /* check that the buffer is ours, all buffers returned to the pool have the
+ * pool member set to NULL and the pool refcount decreased */
+ if (!g_atomic_pointer_compare_and_exchange ((gpointer *) & buffer->pool, pool,
+ NULL))
+ return;
+
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
if (G_LIKELY (pclass->release_buffer))
pclass->release_buffer (pool, buffer);
dec_outstanding (pool);
+
+ /* decrease the refcount that the buffer had to us */
+ gst_object_unref (pool);
}
diff --git a/gst/gstbufferpool.h b/gst/gstbufferpool.h
index 48df0b80b..17f9e516b 100644
--- a/gst/gstbufferpool.h
+++ b/gst/gstbufferpool.h
@@ -32,7 +32,6 @@
G_BEGIN_DECLS
-typedef struct _GstBufferPool GstBufferPool;
typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
typedef struct _GstBufferPoolClass GstBufferPoolClass;