[gst-devel] buffer debugging
vishnu at pobox.com
vishnu at pobox.com
Sat Sep 22 15:48:01 CEST 2001
Here's the idea. (untested)
--
Victory to the Divine Mother!!
http://sahajayoga.org
-------------- next part --------------
Index: gstbuffer.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstbuffer.c,v
retrieving revision 1.36.2.5
diff -u -p -r1.36.2.5 gstbuffer.c
--- gstbuffer.c 2001/09/21 17:31:45 1.36.2.5
+++ gstbuffer.c 2001/09/22 22:46:30
@@ -32,6 +32,9 @@ GType _gst_buffer_type;
static GMemChunk *_gst_buffer_chunk;
static GMutex *_gst_buffer_chunk_lock;
+// This should be conditional compiled only for debugging.
+static glong _debug_buffer_instance = 0;
+
void
_gst_buffer_initialize (void)
{
@@ -67,12 +70,13 @@ _gst_buffer_initialize (void)
* Returns: new buffer
*/
GstBuffer*
-gst_buffer_new (void)
+gst_buffer_new_loc (const gchar *file, gint line)
{
GstBuffer *buffer;
g_mutex_lock (_gst_buffer_chunk_lock);
buffer = g_mem_chunk_alloc (_gst_buffer_chunk);
+ ++_debug_buffer_instance;
g_mutex_unlock (_gst_buffer_chunk_lock);
GST_INFO (GST_CAT_BUFFER,"creating new buffer %p",buffer);
@@ -96,6 +100,9 @@ gst_buffer_new (void)
buffer->free = NULL;
buffer->copy = NULL;
+ buffer->file = file;
+ buffer->line = line;
+
return buffer;
}
@@ -108,18 +115,21 @@ gst_buffer_new (void)
* Returns: new buffer
*/
GstBuffer*
-gst_buffer_new_from_pool (GstBufferPool *pool, guint64 location, gint size)
+gst_buffer_new_from_pool (GstBufferPool *pool, guint32 offset, guint32 size)
{
GstBuffer *buffer;
g_return_val_if_fail (pool != NULL, NULL);
g_return_val_if_fail (pool->buffer_new != NULL, NULL);
- buffer = pool->buffer_new (pool, location, size, pool->user_data);
+ buffer = pool->buffer_new (pool, offset, size, pool->user_data);
buffer->pool = pool;
buffer->free = pool->buffer_free;
buffer->copy = pool->buffer_copy;
+ GST_INFO (GST_CAT_BUFFER,"creating new buffer %p from pool %p (size %x, offset %x)",
+ buffer, pool, size, offset);
+
return buffer;
}
@@ -134,9 +144,11 @@ gst_buffer_new_from_pool (GstBufferPool
* Returns: new buffer
*/
GstBuffer*
-gst_buffer_create_sub (GstBuffer *parent,
- guint32 offset,
- guint32 size)
+gst_buffer_create_sub_loc (const gchar *file,
+ gint line,
+ GstBuffer *parent,
+ guint32 offset,
+ guint32 size)
{
GstBuffer *buffer;
@@ -146,6 +158,7 @@ gst_buffer_create_sub (GstBuffer *parent
g_mutex_lock (_gst_buffer_chunk_lock);
buffer = g_mem_chunk_alloc (_gst_buffer_chunk);
+ ++_debug_buffer_instance;
g_mutex_unlock (_gst_buffer_chunk_lock);
GST_INFO (GST_CAT_BUFFER,"creating new subbuffer %p from parent %p (size %u, offset %u)",
buffer, parent, size, offset);
@@ -184,7 +197,10 @@ gst_buffer_create_sub (GstBuffer *parent
gst_buffer_ref (parent);
buffer->pool = NULL;
- // return the new subbuffer
+
+ buffer->file = file;
+ buffer->line = line;
+
return buffer;
}
@@ -201,8 +217,10 @@ gst_buffer_create_sub (GstBuffer *parent
* Returns: new buffer
*/
GstBuffer*
-gst_buffer_append (GstBuffer *buffer,
- GstBuffer *append)
+gst_buffer_append_loc (const gchar *file,
+ gint line,
+ GstBuffer *buffer,
+ GstBuffer *append)
{
guint size;
GstBuffer *newbuf;
@@ -226,7 +244,7 @@ gst_buffer_append (GstBuffer *buffer,
}
// the buffer is used, create a new one
else {
- newbuf = gst_buffer_new ();
+ newbuf = gst_buffer_new_loc (file, line);
newbuf->size = buffer->size+append->size;
newbuf->data = g_malloc (newbuf->size);
memcpy (newbuf->data, buffer->data, buffer->size);
@@ -250,7 +268,10 @@ gst_buffer_destroy (GstBuffer *buffer)
g_return_if_fail (buffer != NULL);
- GST_INFO (GST_CAT_BUFFER,"freeing %sbuffer %p", (buffer->parent?"sub":""),buffer);
+ GST_INFO (GST_CAT_BUFFER, "freeing %sbuffer %p (%ld buffers remain)",
+ (buffer->parent?"sub":""),
+ buffer,
+ _debug_buffer_instance - 1);
// free the data only if there is some, DONTFREE isn't set, and not sub
if (GST_BUFFER_DATA (buffer) &&
@@ -271,9 +292,15 @@ gst_buffer_destroy (GstBuffer *buffer)
g_mutex_free (buffer->lock);
//g_print("freed mutex\n");
+#ifdef GST_DEBUG_ENABLED
+ // make it hard to reuse by mistake
+ memset (buffer, ~0, sizeof (GstBuffer));
+#endif
+
// remove it entirely from memory
g_mutex_lock (_gst_buffer_chunk_lock);
g_mem_chunk_free (_gst_buffer_chunk,buffer);
+ --_debug_buffer_instance;
g_mutex_unlock (_gst_buffer_chunk_lock);
}
@@ -302,30 +329,6 @@ gst_buffer_ref (GstBuffer *buffer)
}
/**
- * gst_buffer_ref_by_count:
- * @buffer: the GstBuffer to reference
- * @count: a number
- *
- * Increment the refcount of this buffer by the given number.
- */
-void
-gst_buffer_ref_by_count (GstBuffer *buffer, int count)
-{
- g_return_if_fail (buffer != NULL);
- g_return_if_fail (count > 0);
-
-#ifdef HAVE_ATOMIC_H
- g_return_if_fail (atomic_read (&(buffer->refcount)) > 0);
- atomic_add (count, &(buffer->refcount));
-#else
- g_return_if_fail (buffer->refcount > 0);
- GST_BUFFER_LOCK (buffer);
- buffer->refcount += count;
- GST_BUFFER_UNLOCK (buffer);
-#endif
-}
-
-/**
* gst_buffer_unref:
* @buffer: the GstBuffer to unref
*
@@ -367,12 +370,14 @@ gst_buffer_unref (GstBuffer *buffer)
* Returns: new buffer
*/
GstBuffer *
-gst_buffer_copy (GstBuffer *buffer)
+gst_buffer_copy_loc (const gchar *file,
+ gint line,
+ GstBuffer *buffer)
{
GstBuffer *newbuf;
// allocate a new buffer
- newbuf = gst_buffer_new();
+ newbuf = gst_buffer_new_loc (file, line);
// if a copy function exists, use it, else copy the bytes
if (buffer->copy != NULL) {
@@ -436,7 +441,8 @@ gst_buffer_is_span_fast (GstBuffer *buf1
*/
// FIXME need to think about CoW and such...
GstBuffer *
-gst_buffer_span (GstBuffer *buf1, guint32 offset, GstBuffer *buf2, guint32 len)
+gst_buffer_span_loc (const gchar *file, gint line,
+ GstBuffer *buf1, guint32 offset, GstBuffer *buf2, guint32 len)
{
GstBuffer *newbuf;
@@ -453,12 +459,13 @@ gst_buffer_span (GstBuffer *buf1, guint3
// ((buf1->data + buf1->size) == buf2->data)) {
if (gst_buffer_is_span_fast(buf1,buf2)) {
// 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_loc(file, line,
+ buf1->parent, buf1->data - (buf1->parent->data) + offset, len);
}
else {
g_print ("slow path taken in buffer_span\n");
// otherwise we simply have to brute-force copy the buffers
- newbuf = gst_buffer_new();
+ newbuf = gst_buffer_new_loc (file, line);
// put in new size
newbuf->size = len;
@@ -496,8 +503,9 @@ gst_buffer_span (GstBuffer *buf1, guint3
* Returns: new buffer that's the concatenation of the source buffers
*/
GstBuffer *
-gst_buffer_merge (GstBuffer *buf1, GstBuffer *buf2)
+gst_buffer_merge_loc (const gchar *file, gint line,
+ GstBuffer *buf1, GstBuffer *buf2)
{
// we're just a specific case of the more general gst_buffer_span()
- return gst_buffer_span(buf1, 0, buf2, buf1->size + buf2->size);
+ return gst_buffer_span_loc (file, line, buf1, 0, buf2, buf1->size + buf2->size);
}
Index: gstbuffer.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstbuffer.h,v
retrieving revision 1.26.4.1
diff -u -p -r1.26.4.1 gstbuffer.h
--- gstbuffer.h 2001/09/11 09:58:16 1.26.4.1
+++ gstbuffer.h 2001/09/22 22:46:30
@@ -119,9 +119,12 @@ struct _GstBuffer {
guint32 maxsize;
guint32 offset;
+ // where created (debug)
+ const gchar *file;
+ gint line;
+
/* timestamp */
gint64 timestamp;
- /* max age */
gint64 maxage;
/* subbuffer support, who's my parent? */
@@ -139,29 +142,46 @@ struct _GstBuffer {
/* initialisation */
void _gst_buffer_initialize (void);
/* creating a new buffer from scratch */
-GstBuffer* gst_buffer_new (void);
-GstBuffer* gst_buffer_new_from_pool (GstBufferPool *pool, guint64 location, gint size);
+GstBuffer* gst_buffer_new_loc (const gchar *file, gint line);
+GstBuffer* gst_buffer_new_from_pool (GstBufferPool *pool, guint32 offset, guint32 size);
/* creating a subbuffer */
-GstBuffer* gst_buffer_create_sub (GstBuffer *parent, guint32 offset, guint32 size);
+GstBuffer* gst_buffer_create_sub_loc (const gchar *file, gint line,
+ GstBuffer *parent, guint32 offset, guint32 size);
/* refcounting */
void gst_buffer_ref (GstBuffer *buffer);
-void gst_buffer_ref_by_count (GstBuffer *buffer, int count);
void gst_buffer_unref (GstBuffer *buffer);
/* destroying the buffer */
void gst_buffer_destroy (GstBuffer *buffer);
/* copy buffer */
-GstBuffer* gst_buffer_copy (GstBuffer *buffer);
+GstBuffer* gst_buffer_copy_loc (const gchar *file, gint line,
+ GstBuffer *buffer);
/* merge, span, or append two buffers, intelligently */
-GstBuffer* gst_buffer_merge (GstBuffer *buf1, GstBuffer *buf2);
-GstBuffer* gst_buffer_span (GstBuffer *buf1,guint32 offset,GstBuffer *buf2,guint32 len);
-GstBuffer* gst_buffer_append (GstBuffer *buf, GstBuffer *buf2);
+GstBuffer* gst_buffer_merge_loc (const gchar *file, gint line,
+ GstBuffer *buf1, GstBuffer *buf2);
+GstBuffer* gst_buffer_span_loc (const gchar *file, gint line,
+ GstBuffer *buf1,guint32 offset,GstBuffer *buf2,guint32 len);
+GstBuffer* gst_buffer_append_loc (const gchar *file, gint line,
+ GstBuffer *buf, GstBuffer *buf2);
gboolean gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2);
+
+#define gst_buffer_new() \
+ gst_buffer_new_loc(__FILE__, __LINE__)
+#define gst_buffer_create_sub(parent, offset, size) \
+ gst_buffer_create_sub_loc(__FILE__, __LINE__, parent, offset, size)
+#define gst_buffer_copy(buffer) \
+ gst_buffer_copy_loc(__FILE__, __LINE__, buffer)
+#define gst_buffer_merge(buf1, buf2) \
+ gst_buffer_merge_loc(__FILE__, __LINE__, buf1, buf2)
+#define gst_buffer_span(buf1, offset, buf2, len) \
+ gst_buffer_span_loc(__FILE__, __LINE__, buf1, offset, buf2, len)
+#define gst_buffer_append(buf, buf2) \
+ gst_buffer_append_loc(__FILE__, __LINE__, buf, buf2)
#ifdef __cplusplus
}
More information about the gstreamer-devel
mailing list